Module | Sequel::Plugins::Timestamps |
In: |
lib/sequel/plugins/timestamps.rb
|
The timestamps plugin creates hooks that automatically set create and update timestamp fields. Both field names used are configurable, and you can also set whether to overwrite existing create timestamps (false by default), or whether to set the update timestamp when creating (also false by default).
Usage:
# Timestamp all model instances using +created_at+ and +updated_at+ # (called before loading subclasses) Sequel::Model.plugin :timestamps # Timestamp Album instances, with custom column names Album.plugin :timestamps, :create=>:created_on, :update=>:updated_on # Timestamp Artist instances, forcing an overwrite of the create # timestamp, and setting the update timestamp when creating Album.plugin :timestamps, :force=>true, :update_on_create=>true
Configure the plugin by setting the avialable options. Note that if this method is run more than once, previous settings are ignored, and it will just use the settings given or the default settings. Options:
# File lib/sequel/plugins/timestamps.rb, line 29 29: def self.configure(model, opts={}) 30: model.instance_eval do 31: @create_timestamp_field = opts[:create]||:created_at 32: @update_timestamp_field = opts[:update]||:updated_at 33: @create_timestamp_overwrite = opts[:force]||false 34: @set_update_timestamp_on_create = opts[:update_on_create]||false 35: end 36: end