Module: CouchPotato::MagicTimestamps

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

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



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

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.zone || Time).now
      @changed_attributes.delete 'created_at'
      model.updated_at ||= (Time.zone || Time).now
      @changed_attributes.delete 'updated_at'
    }
    before_update lambda {|model|
      model.updated_at = (Time.zone || Time).now
      @changed_attributes.delete 'updated_at'
    }
  end
end