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
74 def before_update
75   set_update_timestamp
76   super
77 end
before_validation() click to toggle source

Set the create timestamp when creating

Calls superclass method
   # File lib/sequel/plugins/timestamps.rb
80 def before_validation
81   set_create_timestamp if new?
82   super
83 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
92 def set_create_timestamp(time=nil)
93   field = model.create_timestamp_field
94   meth = :"#{field}="
95   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?)
96   set_update_timestamp(time) if model.set_update_timestamp_on_create?
97 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
101 def set_update_timestamp(time=nil)
102   return if model.allow_manual_timestamp_update? && modified?(model.update_timestamp_field)
103   meth = :"#{model.update_timestamp_field}="
104   set_column_value(meth, time||model.dataset.current_datetime) if respond_to?(meth)
105 end