Sha256: 5725b147e4c7416bfc3a4dd80695afd482afd3e88666b61126e9ddca7e9d5665
Contents?: true
Size: 856 Bytes
Versions: 18
Compression:
Stored size: 856 Bytes
Contents
module MotionPrime module ModelTimestampsMixin extend ::MotionSupport::Concern def self.included(base) base.class_attribute :_timestamp_attributes end def save time = Time.now trigger_timestamp(:save, time) trigger_timestamp(:create, time) if new_record? super end def trigger_timestamp(action_name, time) field = (_timestamp_attributes || {})[action_name] return unless field self.send(:"#{field}=", time) end module ClassMethods def timestamp_attributes(actions = nil) self._timestamp_attributes ||= {} actions ||= {save: :saved_at, create: :created_at} actions.each do |action_name, field| _timestamp_attributes[action_name.to_sym] = field self.attribute field, type: :time end end end end end
Version data entries
18 entries across 18 versions & 1 rubygems