Class: RailsMachine::Configuration
- Inherits:
-
Object
- Object
- RailsMachine::Configuration
- Defined in:
- lib/rails_machine/configuration.rb
Instance Attribute Summary collapse
-
#init_states ⇒ Object
readonly
Returns the value of attribute init_states.
-
#states ⇒ Object
readonly
Returns the value of attribute states.
-
#transitions ⇒ Object
readonly
Returns the value of attribute transitions.
Instance Method Summary collapse
- #init_state(state) ⇒ Object
-
#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 10 |
# File 'lib/rails_machine/configuration.rb', line 6 def initialize @states = {} @init_states = [] @transitions = Hash.new{|hash,key| hash[key] = [] } end |
Instance Attribute Details
#init_states ⇒ Object (readonly)
Returns the value of attribute init_states.
4 5 6 |
# File 'lib/rails_machine/configuration.rb', line 4 def init_states @init_states end |
#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
#init_state(state) ⇒ Object
17 18 19 |
# File 'lib/rails_machine/configuration.rb', line 17 def init_state(state) @init_states << state end |
#next_id ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/rails_machine/configuration.rb', line 30 def next_id if @states.empty? 0 else @states.values.max.next end end |
#run(&blk) ⇒ Object
Just runs code
13 14 15 |
# File 'lib/rails_machine/configuration.rb', line 13 def run(&blk) self.instance_eval(&blk) end |
#state(name, id: next_id) ⇒ Object
21 22 23 24 |
# File 'lib/rails_machine/configuration.rb', line 21 def state(name, id: next_id) raise ArgumentError, "State :#{name} is already defined" if @states.key?(name) @states[name] = id end |
#transition(from: :any, to: :any, guards: []) ⇒ Object
26 27 28 |
# File 'lib/rails_machine/configuration.rb', line 26 def transition(from: :any, to: :any, guards: []) @transitions[from] << { to: to, guards: guards } end |