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



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

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)


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

def dirty? 
  changed? || @forced_dirty
end

#initialize(attributes = {}) ⇒ Object



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

def initialize(attributes = {})
  super
  # assign_attribute_copies_for_dirty_tracking
end

#is_dirtyObject

marks a model as dirty



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

def is_dirty
  @forced_dirty = true
end