Module: DataMapper::Timestamps

Defined in:
lib/dm-timestamps.rb,
lib/data_mapper/timestamps/version.rb

Defined Under Namespace

Modules: ClassMethods Classes: InvalidTimestampName

Constant Summary collapse

TIMESTAMP_PROPERTIES =
{
  updated_at: [DateTime, ->(_r) { DateTime.now                             }],
  updated_on: [Date,     ->(_r) { Date.today                               }],
  created_at: [DateTime, ->(r) { r.created_at || (DateTime.now if r.new?) }],
  created_on: [Date,     ->(r) { r.created_on || (Date.today   if r.new?) }],
}.freeze
VERSION =
'1.4.0'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(model) ⇒ Object



12
13
14
15
# File 'lib/dm-timestamps.rb', line 12

def self.included(model)
  model.before :save, :set_timestamps_on_save
  model.extend ClassMethods
end

Instance Method Details

#touchObject

Saves the record with the updated_at/on attributes set to the current time.



18
19
20
21
# File 'lib/dm-timestamps.rb', line 18

def touch
  set_timestamps
  save
end