module Sequel::Plugins::Timestamps::InstanceMethods

Public Instance Methods

before_update() click to toggle source

Set the update timestamp when updating

Calls superclass method
# File lib/sequel/plugins/timestamps.rb, line 74
def before_update
  set_update_timestamp
  super
end
before_validation() click to toggle source

Set the create timestamp when creating

Calls superclass method
# File lib/sequel/plugins/timestamps.rb, line 80
def before_validation
  set_create_timestamp if new?
  super
end

Private Instance Methods

set_create_timestamp(time=nil) click to toggle source

If the object has accessor methods for the create timestamp field, and the create timestamp value is nil or overwriting it is allowed, set the create timestamp field to the time given or the current time. If setting the update timestamp on creation is configured, set the update timestamp as well.

# File lib/sequel/plugins/timestamps.rb, line 92
def set_create_timestamp(time=nil)
  field = model.create_timestamp_field
  meth = :"#{field}="
  set_column_value(meth, time||=model.dataset.current_datetime) if respond_to?(field) && respond_to?(meth) && (model.create_timestamp_overwrite? || get_column_value(field).nil?)
  set_update_timestamp(time) if model.set_update_timestamp_on_create?
end
set_update_timestamp(time=nil) click to toggle source

Set the update timestamp to the time given or the current time if the object has a setter method for the update timestamp field.

# File lib/sequel/plugins/timestamps.rb, line 101
def set_update_timestamp(time=nil)
  return if model.allow_manual_timestamp_update? && modified?(model.update_timestamp_field)
  meth = :"#{model.update_timestamp_field}="
  set_column_value(meth, time||model.dataset.current_datetime) if respond_to?(meth)
end