Module: MassiveRecord::ORM::AttributeMethods::Dirty
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Dirty
- Defined in:
- lib/massive_record/orm/attribute_methods/dirty.rb
Instance Method Summary collapse
- #changed ⇒ Object
- #changed? ⇒ Boolean
- #changes ⇒ Object
- #reload ⇒ Object
- #save ⇒ Object
- #save! ⇒ Object
- #write_attribute(attr_name, value) ⇒ Object
Instance Method Details
#changed ⇒ Object
52 53 54 |
# File 'lib/massive_record/orm/attribute_methods/dirty.rb', line 52 def changed super + .select(&:changed?).collect { |proxy| proxy..name } end |
#changed? ⇒ Boolean
48 49 50 |
# File 'lib/massive_record/orm/attribute_methods/dirty.rb', line 48 def changed? super || .any?(&:changed?) end |
#changes ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/massive_record/orm/attribute_methods/dirty.rb', line 56 def changes = {} .select(&:changed?).each do |proxy| [proxy..name] = proxy.changes end super.update() end |
#reload ⇒ Object
26 27 28 29 30 |
# File 'lib/massive_record/orm/attribute_methods/dirty.rb', line 26 def reload(*) super.tap do clear_dirty_states! end end |
#save ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/massive_record/orm/attribute_methods/dirty.rb', line 9 def save(*) if status = super changes_before_save = changes clear_dirty_states! @previously_changed = changes_before_save end status end |
#save! ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/massive_record/orm/attribute_methods/dirty.rb', line 18 def save!(*) super.tap do changes_before_save = changes clear_dirty_states! @previously_changed = changes_before_save end end |
#write_attribute(attr_name, value) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/massive_record/orm/attribute_methods/dirty.rb', line 32 def write_attribute(attr_name, value) attr_name = attr_name.to_s if will_change_attribute?(attr_name, value) if will_change_back_to_original_value?(attr_name, value) changed_attributes.delete(attr_name) else super(attr_name, original_attribute_value(attr_name)) send("#{attr_name}_will_change!") end end super end |