Module: Familia::Stamps

Included in:
Customer, Session
Defined in:
lib/familia/helpers.rb

Overview

class Example

  include Familia
  field :name
  include Familia::Stamps
end

Class Method Summary collapse

Class Method Details

.included(obj) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/familia/helpers.rb', line 11

def self.included(obj)
  obj.module_eval do
    field :created => Integer
    field :updated => Integer
    def init_stamps
      now = Time.now.utc.to_i
      @created ||= now
      @updated ||= now 
    end
    def created
      @created ||= Time.now.utc.to_i
    end
    def updated
      @updated ||= Time.now.utc.to_i
    end
    def created_age
      Time.now.utc.to_i-created
    end
    def updated_age
      Time.now.utc.to_i-updated
    end
    def update_time
      @updated = Time.now.utc.to_i
    end
    def update_time!
      update_time
      save if respond_to? :save
      @updated
    end
  end
end