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

Instance Method Details

#changedObject



52
53
54
# File 'lib/massive_record/orm/attribute_methods/dirty.rb', line 52

def changed
  super + relation_proxies_for_embedded.select(&:changed?).collect { |proxy| proxy..name }
end

#changed?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/massive_record/orm/attribute_methods/dirty.rb', line 48

def changed?
  super || relation_proxies_for_embedded.any?(&:changed?)
end

#changesObject



56
57
58
59
60
61
62
63
64
# File 'lib/massive_record/orm/attribute_methods/dirty.rb', line 56

def changes
  changes_in_embedded_proxies = {}

  relation_proxies_for_embedded.select(&:changed?).each do |proxy|
    changes_in_embedded_proxies[proxy..name] = proxy.changes 
  end

  super.update(changes_in_embedded_proxies)
end

#reloadObject



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

#saveObject



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