Module: Tripod::Dirty

Extended by:
ActiveSupport::Concern
Included in:
Components, EmbeddedResource
Defined in:
lib/tripod/dirty.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#attribute_change(attr) ⇒ Object



24
25
26
# File 'lib/tripod/dirty.rb', line 24

def attribute_change(attr)
  [ changed_attributes[attr], read_attribute(attr) ] if attribute_changed?(attr)
end

#attribute_changed?(attr) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/tripod/dirty.rb', line 28

def attribute_changed?(attr)
  return false unless changed_attributes.has_key?(attr)
  (changed_attributes[attr] != read_attribute(attr))
end

#attribute_will_change!(attr) ⇒ Object



20
21
22
# File 'lib/tripod/dirty.rb', line 20

def attribute_will_change!(attr)
  changed_attributes[attr] = read_attribute(attr) unless changed_attributes.has_key?(attr)
end

#changedObject



8
9
10
# File 'lib/tripod/dirty.rb', line 8

def changed
  changed_attributes.keys
end

#changed_attributesObject



4
5
6
# File 'lib/tripod/dirty.rb', line 4

def changed_attributes
  @changed_attributes ||= {}
end

#changesObject



12
13
14
15
16
17
18
# File 'lib/tripod/dirty.rb', line 12

def changes
  changed.reduce({}) do |memo, attr|
    change = attribute_change(attr)
    memo[attr] = change if change
    memo
  end
end

#post_persistObject



33
34
35
# File 'lib/tripod/dirty.rb', line 33

def post_persist
  changed_attributes.clear
end