Module: Sequel::Plugins::StateMachine::ClassMethods
- Defined in:
- lib/sequel/plugins/state_machine.rb
Instance Method Summary collapse
-
#timestamp_accessor(event, accessor) ⇒ Object
Register the timestamp access for an event.
- #timestamp_accessors(events_and_accessors) ⇒ Object
Instance Method Details
#timestamp_accessor(event, accessor) ⇒ Object
Register the timestamp access for an event. A timestamp accessor reads when a certain transition happened by looking at the timestamp of the successful transition into that state.
The event can be just the event name, or a hash of <event method symbol>, from: <state name>, used when a single event can cause multiple transitions.
152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/sequel/plugins/state_machine.rb', line 152 def (event, accessor) define_method(accessor) do event = {event: event} if event.is_a?(String) audit = self.audit_logs.select(&:succeeded?).find do |a| ev_match = event[:event].nil? || event[:event] == a.event from_match = event[:from].nil? || event[:from] == a.from_state to_match = event[:to].nil? || event[:to] == a.to_state ev_match && from_match && to_match end return audit&.at end end |
#timestamp_accessors(events_and_accessors) ⇒ Object
140 141 142 143 144 |
# File 'lib/sequel/plugins/state_machine.rb', line 140 def (events_and_accessors) events_and_accessors.each do |(ev, acc)| self.(ev, acc) end end |