Class: ActiveRecord::Fsm::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord/fsm/graph.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

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_klassesObject



23
24
25
# File 'lib/activerecord/fsm/graph.rb', line 23

def defined_klasses
  @defined_klasses ||= []
end

Instance Attribute Details

#final_statesObject

Returns the value of attribute final_states.



4
5
6
# File 'lib/activerecord/fsm/graph.rb', line 4

def final_states
  @final_states
end

#statesObject

Returns the value of attribute states.



4
5
6
# File 'lib/activerecord/fsm/graph.rb', line 4

def states
  @states
end

#transitionsObject

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

Returns:

  • (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

Returns:

  • (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