Class: Listen::FSM::State
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/fsm.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#transitions ⇒ Object
readonly
Returns the value of attribute transitions.
Instance Method Summary collapse
- #call(obj) ⇒ Object
-
#initialize(name, transitions, &block) ⇒ State
constructor
A new instance of State.
- #valid_transition?(new_state) ⇒ Boolean
Constructor Details
#initialize(name, transitions, &block) ⇒ State
Returns a new instance of State.
115 116 117 118 119 120 121 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/fsm.rb', line 115 def initialize(name, transitions, &block) @name = name @block = block @transitions = if transitions Array(transitions).map(&:to_sym) end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
113 114 115 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/fsm.rb', line 113 def name @name end |
#transitions ⇒ Object (readonly)
Returns the value of attribute transitions.
113 114 115 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/fsm.rb', line 113 def transitions @transitions end |
Instance Method Details
#call(obj) ⇒ Object
123 124 125 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/fsm.rb', line 123 def call(obj) obj.instance_eval(&@block) if @block end |
#valid_transition?(new_state) ⇒ Boolean
127 128 129 130 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/fsm.rb', line 127 def valid_transition?(new_state) # All transitions are allowed if none are expressly declared !@transitions || @transitions.include?(new_state.to_sym) end |