Module: CouchPotato::MagicTimestamps

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

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/couch_potato/persistence/magic_timestamps.rb', line 3

def self.included(base)
  base.instance_eval do
    property :created_at, :type => Time
    property :updated_at, :type => Time
    
    before_create lambda {|model|
      model.created_at ||= Time.now
      @changed_attributes.delete 'created_at'
      model.updated_at ||= Time.now
      @changed_attributes.delete 'updated_at'
    }
    before_update lambda {|model|
      model.updated_at = Time.now
      @changed_attributes.delete 'updated_at'
    }
  end
end