Module: NxtStateMachine::ClassMethods
- Includes:
- NxtRegistry
- Defined in:
- lib/nxt_state_machine.rb
Instance Method Summary collapse
- #new(*args, **opts, &block) ⇒ Object
- #state_machine(name = :default, **opts, &config) ⇒ Object
- #state_machines ⇒ Object
Instance Method Details
#new(*args, **opts, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/nxt_state_machine.rb', line 50 def new(*args, **opts, &block) instance = if opts.any? super(*args, **opts, &block) else super(*args, &block) end # set each initial state for all machines state_machines.each do |name, machine| instance.current_state_name(name) if machine.initial_state.present? end instance end |
#state_machine(name = :default, **opts, &config) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/nxt_state_machine.rb', line 39 def state_machine(name = :default, **opts, &config) state_machines.resolve(name) || state_machines.register( name, StateMachine.new(name, self, state_machine_event_registry, **opts).configure(&config) ) end |
#state_machines ⇒ Object
46 47 48 |
# File 'lib/nxt_state_machine.rb', line 46 def state_machines @state_machines ||= registry :state_machines end |