module Rmodel::RepositoryExt::Timestampable
Public Instance Methods
insert_one(object)
click to toggle source
Calls superclass method
# File lib/rmodel/repository_ext/timestampable.rb, line 4 def insert_one(object) time = now object.created_at = time if able_to_set_created_at?(object) object.updated_at = time if able_to_set_updated_at?(object) super end
update(object)
click to toggle source
Calls superclass method
# File lib/rmodel/repository_ext/timestampable.rb, line 11 def update(object) object.updated_at = now if able_to_set_updated_at?(object) super end
Private Instance Methods
able_to_set_created_at?(object)
click to toggle source
# File lib/rmodel/repository_ext/timestampable.rb, line 18 def able_to_set_created_at?(object) object.respond_to?(:created_at=) && object.created_at.nil? end
able_to_set_updated_at?(object)
click to toggle source
# File lib/rmodel/repository_ext/timestampable.rb, line 22 def able_to_set_updated_at?(object) object.respond_to?(:updated_at=) end
now()
click to toggle source
# File lib/rmodel/repository_ext/timestampable.rb, line 26 def now Time.try(:current) || Time.now end