Class: Stately::State
- Inherits:
-
Object
- Object
- Stately::State
- Defined in:
- lib/stately/state.rb
Overview
A Stately::State object contains the configuration and other information about a defined state.
It’s made up of a name (which is saved to the parent instance’s state attribute), the name of an action (which is a method called to transition into this state), and a DSL to define allowed transitions, callbacks, and validations.
Defined Under Namespace
Classes: StateConfigurator
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#after_transitions ⇒ Object
readonly
Returns the value of attribute after_transitions.
-
#allow_from_states ⇒ Object
readonly
Returns the value of attribute allow_from_states.
-
#before_transitions ⇒ Object
readonly
Returns the value of attribute before_transitions.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#prevent_from_states ⇒ Object
readonly
Returns the value of attribute prevent_from_states.
-
#validations ⇒ Object
readonly
Returns the value of attribute validations.
Instance Method Summary collapse
-
#initialize(name, action = nil, &block) ⇒ State
constructor
Sets up and returns a new Stately::State object.
-
#to_s ⇒ String
The state name as a string.
-
#to_sym ⇒ Symbol
The state name as a string.
Constructor Details
#initialize(name, action = nil, &block) ⇒ State
Sets up and returns a new Stately::State object.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/stately/state.rb', line 19 def initialize(name, action=nil, &block) @action = (action || guess_action_for(name)).to_s @name = name @allow_from_states = [] @prevent_from_states = [] @before_transitions = [] @after_transitions = [] @validations = [] if block_given? configuration = StateConfigurator.new(&block) @allow_from_states = configuration.allow_from_states || [] @prevent_from_states = configuration.prevent_from_states || [] @after_transitions = configuration.after_transitions || [] @before_transitions = configuration.before_transitions || [] @validations = configuration.validations || [] end end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
10 11 12 |
# File 'lib/stately/state.rb', line 10 def action @action end |
#after_transitions ⇒ Object (readonly)
Returns the value of attribute after_transitions.
12 13 14 |
# File 'lib/stately/state.rb', line 12 def after_transitions @after_transitions end |
#allow_from_states ⇒ Object (readonly)
Returns the value of attribute allow_from_states.
11 12 13 |
# File 'lib/stately/state.rb', line 11 def allow_from_states @allow_from_states end |
#before_transitions ⇒ Object (readonly)
Returns the value of attribute before_transitions.
12 13 14 |
# File 'lib/stately/state.rb', line 12 def before_transitions @before_transitions end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/stately/state.rb', line 10 def name @name end |
#prevent_from_states ⇒ Object (readonly)
Returns the value of attribute prevent_from_states.
11 12 13 |
# File 'lib/stately/state.rb', line 11 def prevent_from_states @prevent_from_states end |
#validations ⇒ Object (readonly)
Returns the value of attribute validations.
12 13 14 |
# File 'lib/stately/state.rb', line 12 def validations @validations end |
Instance Method Details
#to_s ⇒ String
Returns The state name as a string.
43 44 45 |
# File 'lib/stately/state.rb', line 43 def to_s @name.to_s end |
#to_sym ⇒ Symbol
Returns The state name as a string.
48 49 50 |
# File 'lib/stately/state.rb', line 48 def to_sym @name.to_sym end |