Module: Vault::Dirty

Extended by:
ActiveSupport::Concern
Defined in:
lib/vault/dirty.rb

Instance Method Summary collapse

Instance Method Details

#saveObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vault/dirty.rb', line 9

def save(*)
  super.tap do |saved|
    if saved
      if attribute_changed?(self.class.key)
        self.class.store.delete(attribute_was(self.class.key))
      end

      @previously_changed = changes
      changed_attributes.clear
    end
  end
end

#write_attribute(name, value) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vault/dirty.rb', line 22

def write_attribute(name, value)
  name = name.to_s

  if attribute_changed?(name)
    old = changed_attributes[name]
    changed_attributes.delete(name) if old == value
  else
    old = read_attribute(name)
    old = old.dup if old.duplicable?
    changed_attributes[name] = old if old != value
  end

  super(name, value)
end