модуль ActiveRecord::AttributeMethods::Dirty
Публичные методы экземпляров
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 165 def attribute_before_last_save(attr_name) mutations_before_last_save.original_value(attr_name) end
Возвращает исходное значение атрибута перед последним сохранением. Ведёт себя аналогично attribute_was. Этот метод полезен в после-обработках, чтобы получить исходное значение атрибута перед сохранением, которое только что произошло.
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 219
def attribute_change(*)
emit_warning_if_needed("attribute_change", "saved_change_to_attribute")
super
end # File activerecord/lib/active_record/attribute_methods/dirty.rb, line 185 def attribute_change_to_be_saved(attr_name) mutations_from_database.change_to_attribute(attr_name) end
Псевдоним для `attribute_change`
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 224
def attribute_changed?(*)
emit_warning_if_needed("attribute_changed?", "saved_change_to_attribute?")
super
end # File activerecord/lib/active_record/attribute_methods/dirty.rb, line 190 def attribute_in_database(attr_name) mutations_from_database.original_value(attr_name) end
Псевдоним для `attribute_was`
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 214
def attribute_was(*)
emit_warning_if_needed("attribute_was", "attribute_before_last_save")
super
end # File activerecord/lib/active_record/attribute_methods/dirty.rb, line 210 def attributes_in_database changes_to_save.transform_values(&:first) end
Псевдоним для `changed_attributes`
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 234
def changed(*)
emit_warning_if_needed("changed", "saved_changes.keys")
super
end # File activerecord/lib/active_record/attribute_methods/dirty.rb, line 229
def changed?(*)
emit_warning_if_needed("changed?", "saved_changes?")
super
end # File activerecord/lib/active_record/attribute_methods/dirty.rb, line 205 def changed_attribute_names_to_save changes_to_save.keys end
Псевдоним для `changed`
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 200 def changes_to_save mutations_from_database.changes end
Псевдоним для `changes`
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 195 def has_changes_to_save? mutations_from_database.any_changes? end
Псевдоним для `changed?`
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 48
def reload(*)
super.tap do
@previous_mutation_tracker = nil
clear_mutation_trackers
@changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
end
end reload запись и очищает изменённые атрибуты.
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 33
def save(*)
if status = super
changes_applied
end
status
end Попытка save записи и очищает изменённые атрибуты, если успешно.
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 41
def save!(*)
super.tap do
changes_applied
end
end Попытка save! записи и очищает изменённые атрибуты, если успешно.
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 157 def saved_change_to_attribute(attr_name) mutations_before_last_save.change_to_attribute(attr_name) end
Возвращает изменение атрибута во время последнего сохранения. Если атрибут был изменён, результат будет массивом, содержащим исходное значение и сохранённое значение.
Ведёт себя аналогично attribute_change. Этот метод полезен в после-обработках, чтобы увидеть изменение атрибута, которое только что произошло.
Этот метод может вызываться как `saved_change_to_name` вместо `saved_change_to_attribute(“name”)`
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 144 def saved_change_to_attribute?(attr_name, **options) mutations_before_last_save.changed?(attr_name, **options) end
Было ли изменено этот атрибут при последнем сохранении? Этот метод может вызываться как `saved_change_to_name?` вместо `saved_change_to_attribute?(“name”)`. Ведёт себя аналогично attribute_changed?. Этот метод полезен в после-обработках, чтобы определить, изменил ли вызов сохранения определённый атрибут.
Опции
from При передаче, этот метод вернёт false, если исходное значение не равно указанному параметру.
to При передаче, этот метод вернёт false, если значение не было изменено на указанное значение.
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 175 def saved_changes mutations_before_last_save.changes end
Возвращает словарь, содержащий все изменения, которые были только что сохранены.
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 170 def saved_changes? mutations_before_last_save.any_changes? end
Были ли изменения при последнем вызове `save`?
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 180 def will_save_change_to_attribute?(attr_name, **options) mutations_from_database.changed?(attr_name, **options) end
Псевдоним для `attribute_changed?`
© 2004–2018 David Heinemeier Hansson
Licensed under the MIT License.