Class: ActiveRecord::Fsm::Graph
- Inherits:
-
Object
- Object
- ActiveRecord::Fsm::Graph
- Defined in:
- lib/activerecord/fsm/graph.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#final_states ⇒ Object
Returns the value of attribute final_states.
-
#states ⇒ Object
Returns the value of attribute states.
-
#transitions ⇒ Object
Returns the value of attribute transitions.
Instance Method Summary collapse
- #final_state?(state) ⇒ Boolean
-
#initialize(transitions) ⇒ Graph
constructor
A new instance of Graph.
- #valid_transition?(cur_state, tar_state) ⇒ Boolean
Constructor Details
#initialize(transitions) ⇒ Graph
Returns a new instance of Graph.
6 7 8 9 10 |
# File 'lib/activerecord/fsm/graph.rb', line 6 def initialize(transitions) @transitions = transitions @states = transitions.flatten.uniq @final_states = (transitions.map(&:last) - transitions.map(&:first)).uniq end |
Class Attribute Details
.defined_klasses ⇒ Object
23 24 25 |
# File 'lib/activerecord/fsm/graph.rb', line 23 def defined_klasses @defined_klasses ||= [] end |
Instance Attribute Details
#final_states ⇒ Object
Returns the value of attribute final_states.
4 5 6 |
# File 'lib/activerecord/fsm/graph.rb', line 4 def final_states @final_states end |
#states ⇒ Object
Returns the value of attribute states.
4 5 6 |
# File 'lib/activerecord/fsm/graph.rb', line 4 def states @states end |
#transitions ⇒ Object
Returns the value of attribute transitions.
4 5 6 |
# File 'lib/activerecord/fsm/graph.rb', line 4 def transitions @transitions end |
Instance Method Details
#final_state?(state) ⇒ Boolean
16 17 18 |
# File 'lib/activerecord/fsm/graph.rb', line 16 def final_state?(state) final_states.include?(state) end |
#valid_transition?(cur_state, tar_state) ⇒ Boolean
12 13 14 |
# File 'lib/activerecord/fsm/graph.rb', line 12 def valid_transition?(cur_state, tar_state) transitions.include?([cur_state, tar_state]) end |