Sha256: 4f619868515a8875b62fd1895a016b8a62845def4c1b3fcfcd27ea4b58c0cd1c
Contents?: true
Size: 705 Bytes
Versions: 2
Compression:
Stored size: 705 Bytes
Contents
module Statesman class EventTransitions attr_reader :machine, :event_name def initialize(machine, event_name, &block) @machine = machine @event_name = event_name instance_eval(&block) end def transition(from: nil, to: nil) from = to_s_or_nil(from) to = array_to_s_or_nil(to) machine.transition(from: from, to: to) machine.events[event_name] ||= {} machine.events[event_name][from] ||= [] machine.events[event_name][from] += to end private def to_s_or_nil(input) input.nil? ? input : input.to_s end def array_to_s_or_nil(input) Array(input).map { |item| to_s_or_nil(item) } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
statesman-events-1.0.0 | lib/statesman/event_transitions.rb |
statesman-events-0.0.1 | lib/statesman/event_transitions.rb |