Module: Mince::DataModel::Timestamps
- Extended by:
- ActiveSupport::Concern
- Includes:
- Mince::DataModel
- Defined in:
- lib/mince/data_model/timestamps.rb
Overview
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.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Methods included from Mince::DataModel
#add_to_interface, #attributes, #create, #data_collection, #data_fields, #infer_fields?, #initialize, #interface, #replace_in_interface, #timestamps?, #update
Instance Method Details
#timestamp_attributes ⇒ Object
55 56 57 |
# File 'lib/mince/data_model/timestamps.rb', line 55 def { created_at: created_at, updated_at: updated_at } end |
#update_timestamps ⇒ Object
49 50 51 52 53 |
# File 'lib/mince/data_model/timestamps.rb', line 49 def now = Time.now.utc self.created_at = now unless created_at self.updated_at = now end |