module Mince::DataModel::Timestamps
Timestamps
¶ ↑
Timestamps
can be mixed into your DataModel
classes in order to provide with fields to store when records are created and updated.
Example:
require 'mince/data_model' Class UserDataModel include Mince::DataModel include Mince::DataModel::Timestamps data_collection :users data_fields :username end UserDataModel.add username: 'coffeencoke' data_model = UserDataModel.find_by_field :username, 'coffeencoke' data_model.created_at # => todo: returns date time in utc data_model.updated_at # => todo: returns date time in utc
Whenever a database persisting message is called for a record, the updated_at timestamp will be updated.
Public Instance Methods
timestamp_attributes()
click to toggle source
# File lib/mince/data_model/timestamps.rb, line 55 def timestamp_attributes { created_at: created_at, updated_at: updated_at } end
update_timestamps()
click to toggle source
# File lib/mince/data_model/timestamps.rb, line 49 def update_timestamps now = Time.now.utc self.created_at = now unless created_at self.updated_at = now end