Class: RailsMachine::Configuration
- Inherits:
-
Object
- Object
- RailsMachine::Configuration
- Defined in:
- lib/rails_machine/configuration.rb
Instance Attribute Summary collapse
-
#states ⇒ Object
readonly
Returns the value of attribute states.
-
#transitions ⇒ Object
readonly
Returns the value of attribute transitions.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #next_id ⇒ Object
-
#run(&blk) ⇒ Object
Just runs code.
- #state(name, id: next_id) ⇒ Object
- #transition(from: :any, to: :any, guards: []) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
6 7 8 9 |
# File 'lib/rails_machine/configuration.rb', line 6 def initialize @states ||= [] @transitions ||= {} end |
Instance Attribute Details
#states ⇒ Object (readonly)
Returns the value of attribute states.
4 5 6 |
# File 'lib/rails_machine/configuration.rb', line 4 def states @states end |
#transitions ⇒ Object (readonly)
Returns the value of attribute transitions.
4 5 6 |
# File 'lib/rails_machine/configuration.rb', line 4 def transitions @transitions end |
Instance Method Details
#next_id ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/rails_machine/configuration.rb', line 24 def next_id if @states.empty? 0 else @states.map(&:second).max.next end end |
#run(&blk) ⇒ Object
Just runs code
12 13 14 |
# File 'lib/rails_machine/configuration.rb', line 12 def run(&blk) self.instance_eval(&blk) end |
#state(name, id: next_id) ⇒ Object
16 17 18 |
# File 'lib/rails_machine/configuration.rb', line 16 def state(name, id: next_id) @states << [name, id] end |
#transition(from: :any, to: :any, guards: []) ⇒ Object
20 21 22 |
# File 'lib/rails_machine/configuration.rb', line 20 def transition(from: :any, to: :any, guards: []) (@transitions[from] ||= [])<< { to: to, guards: guards } end |