Module: CouchPotato::Persistence::DeepDirtyAttributes

Defined in:
lib/couch_potato/persistence/deep_dirty_attributes.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



5
6
7
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 5

def self.included(base) #:nodoc:
  base.send :extend, ClassMethods
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 14

def changed?
  super || self.class.deep_tracked_properties.any? do |property|
    send("#{property.name}_changed?")
  end
end

#changesObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 20

def changes
  changes = super
  if @original_deep_values
    self.class.deep_tracked_properties.each do |property|
      if send("#{property.name}_changed?")
        changes[property.name] = send("#{property.name}_change")
      else
        changes.delete property.name
      end
    end
  end
  changes
end

#initialize(*args, &block) ⇒ Object



9
10
11
12
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 9

def initialize(*args, &block)
  super(*args, &block)
  reset_deep_dirty_attributes
end