Module: CouchPotato::Persistence::DirtyAttributes

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

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/couch_potato/persistence/dirty_attributes.rb', line 27

def method_missing(name, *args)
  if(name.to_s.include?('_will_change!'))
    self.class.define_attribute_methods self.class.property_names
    send(name, *args)
  else
    super
  end
end

Class Method Details

.included(base) ⇒ Object

:nodoc:



6
7
8
9
10
11
# File 'lib/couch_potato/persistence/dirty_attributes.rb', line 6

def self.included(base) #:nodoc:
  base.send :include, ActiveModel::Dirty
  base.class_eval do
    after_save :reset_dirty_attributes
  end
end

Instance Method Details

#dirty?Boolean

returns true if a model has dirty attributes, i.e. their value has changed since the last save

Returns:

  • (Boolean)


18
19
20
# File 'lib/couch_potato/persistence/dirty_attributes.rb', line 18

def dirty? 
  changed? || @forced_dirty
end

#initialize(attributes = {}) ⇒ Object



13
14
15
# File 'lib/couch_potato/persistence/dirty_attributes.rb', line 13

def initialize(attributes = {})
  super
end

#is_dirtyObject

marks a model as dirty



23
24
25
# File 'lib/couch_potato/persistence/dirty_attributes.rb', line 23

def is_dirty
  @forced_dirty = true
end