module DataMapper::Timestamp

Constants

TIMESTAMP_PROPERTIES

Public Class Methods

included(model) click to toggle source
# File lib/dm-timestamps.rb, line 12
def self.included(model)
  model.before :save, :set_timestamps_on_save
  model.extend ClassMethods
end

Public Instance Methods

touch() click to toggle source

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

# File lib/dm-timestamps.rb, line 18
def touch
  set_timestamps
  save
end

Private Instance Methods

set_timestamps() click to toggle source
# File lib/dm-timestamps.rb, line 30
def set_timestamps
  TIMESTAMP_PROPERTIES.each do |name,(_type,proc)|
    if properties.named?(name)
      attribute_set(name, proc.call(self))
    end
  end
end
set_timestamps_on_save() click to toggle source
# File lib/dm-timestamps.rb, line 25
def set_timestamps_on_save
  return unless dirty?
  set_timestamps
end