Module: Toy::Timestamps::ClassMethods

Defined in:
lib/toy/timestamps.rb

Instance Method Summary collapse

Instance Method Details

#timestampsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/toy/timestamps.rb', line 8

def timestamps
  attribute(:created_at, Time)
  attribute(:updated_at, Time)

  before_create do |record|
    now = Time.now
    record.created_at = now unless created_at?
    record.updated_at = now
  end

  before_update do |record|
    record.updated_at = Time.now
  end
end