Class: StateMachina::State
- Inherits:
-
Object
- Object
- StateMachina::State
- Defined in:
- lib/state_machina/state.rb
Instance Attribute Summary collapse
-
#machine ⇒ Object
Returns the value of attribute machine.
-
#machine_name ⇒ Object
readonly
Returns the value of attribute machine_name.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#model_name ⇒ Object
readonly
Returns the value of attribute model_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #before?(other_state_name) ⇒ Boolean
- #before_inclusive?(other_state_name) ⇒ Boolean
- #between?(from_state_name, to_state_name) ⇒ Boolean
- #between_inclusive?(from_state_name, to_state_name) ⇒ Boolean
-
#initialize(model_name, machine_name, name, metadata: {}) ⇒ State
constructor
A new instance of State.
- #past?(other_state_name) ⇒ Boolean
- #past_inclusive?(other_state_name) ⇒ Boolean
Constructor Details
#initialize(model_name, machine_name, name, metadata: {}) ⇒ State
Returns a new instance of State.
6 7 8 9 10 11 |
# File 'lib/state_machina/state.rb', line 6 def initialize(model_name, machine_name, name, metadata: {}) @model_name = model_name @machine_name = machine_name @name = name.to_s @metadata = end |
Instance Attribute Details
#machine ⇒ Object
Returns the value of attribute machine.
4 5 6 |
# File 'lib/state_machina/state.rb', line 4 def machine @machine end |
#machine_name ⇒ Object (readonly)
Returns the value of attribute machine_name.
3 4 5 |
# File 'lib/state_machina/state.rb', line 3 def machine_name @machine_name end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
3 4 5 |
# File 'lib/state_machina/state.rb', line 3 def @metadata end |
#model_name ⇒ Object (readonly)
Returns the value of attribute model_name.
3 4 5 |
# File 'lib/state_machina/state.rb', line 3 def model_name @model_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/state_machina/state.rb', line 3 def name @name end |
Instance Method Details
#before?(other_state_name) ⇒ Boolean
13 14 15 16 17 |
# File 'lib/state_machina/state.rb', line 13 def before?(other_state_name) return false if machine.nil? machine.states.before(other_state_name).map(&:name).include?(machine.current_state_name) end |
#before_inclusive?(other_state_name) ⇒ Boolean
19 20 21 22 23 |
# File 'lib/state_machina/state.rb', line 19 def before_inclusive?(other_state_name) return false if machine.nil? machine.states.before_inclusive(other_state_name).map(&:name).include?(machine.current_state_name) end |
#between?(from_state_name, to_state_name) ⇒ Boolean
37 38 39 40 41 |
# File 'lib/state_machina/state.rb', line 37 def between?(from_state_name, to_state_name) return false if machine.nil? machine.states.between(from_state_name, to_state_name).map(&:name).include?(machine.current_state_name) end |
#between_inclusive?(from_state_name, to_state_name) ⇒ Boolean
43 44 45 46 47 |
# File 'lib/state_machina/state.rb', line 43 def between_inclusive?(from_state_name, to_state_name) return false if machine.nil? machine.states.between_inclusive(from_state_name, to_state_name).map(&:name).include?(machine.current_state_name) end |
#past?(other_state_name) ⇒ Boolean
25 26 27 28 29 |
# File 'lib/state_machina/state.rb', line 25 def past?(other_state_name) return false if machine.nil? machine.states.past(other_state_name).map(&:name).include?(machine.current_state_name) end |
#past_inclusive?(other_state_name) ⇒ Boolean
31 32 33 34 35 |
# File 'lib/state_machina/state.rb', line 31 def past_inclusive?(other_state_name) return false if machine.nil? machine.states.past_inclusive(other_state_name).map(&:name).include?(machine.current_state_name) end |