Module: MotionPrime::ModelTimestampsMixin

Extended by:
MotionSupport::Concern
Included in:
Model
Defined in:
motion-prime/models/_timestamps_mixin.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'motion-prime/models/_timestamps_mixin.rb', line 5

def self.included(base)
  base.class_attribute :_timestamp_attributes
end

Instance Method Details

#save!Object



9
10
11
12
13
14
# File 'motion-prime/models/_timestamps_mixin.rb', line 9

def save!
  time = Time.now
  trigger_timestamp(:save, time)
  trigger_timestamp(:create, time) if new_record?
  super
end

#trigger_timestamp(action_name, time) ⇒ Object



16
17
18
19
20
# File 'motion-prime/models/_timestamps_mixin.rb', line 16

def trigger_timestamp(action_name, time)
  field = (_timestamp_attributes || {})[action_name]
  return unless field
  self.send(:"#{field}=", time)
end