Module: Fera::HasTimestampAction::ClassMethods
- Defined in:
- lib/fera/models/concerns/has_timestamp_action.rb
Instance Method Summary collapse
-
#timestamp_action(args) ⇒ Object
define API actions that set a timestamp on the model.
Instance Method Details
#timestamp_action(args) ⇒ Object
define API actions that set a timestamp on the model
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fera/models/concerns/has_timestamp_action.rb', line 29 def (args) args.each do |action, state| define_method("#{ action }!") do |at = nil| changed_attributes = { "#{ state }_at": at.presence || Time.now.utc } put(action, changed_attributes) load(changed_attributes) true end define_method("#{ state }?") do send("#{ state }_at?") end define_singleton_method("#{ action }!") do |id, at = nil| find(id).send("#{ action }!", at) end end end |