Class: Statecraft::Machine::Compiler
- Inherits:
-
Object
- Object
- Statecraft::Machine::Compiler
- Defined in:
- lib/statecraft/machine.rb
Overview
Validates the declarations and produces the deep-frozen graph. All five compilation errors live here, plus symbol resolution: every Symbol guard or callback must exist as an instance method of the machine class at finalization time (never checked at the declaration line, so a guard may be declared above its def).
Instance Method Summary collapse
- #compile ⇒ Object
-
#initialize(machine_class) ⇒ Compiler
constructor
A new instance of Compiler.
Constructor Details
#initialize(machine_class) ⇒ Compiler
Returns a new instance of Compiler.
204 205 206 |
# File 'lib/statecraft/machine.rb', line 204 def initialize(machine_class) @machine_class = machine_class end |
Instance Method Details
#compile ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/statecraft/machine.rb', line 208 def compile states = compile_states initial = compile_initial(states) edges = compile_edges(states) events = compile_events(edges) resolve_symbols(edges) assert_record_guards_unary(edges) assert_input_guards_binary(edges) assert_states_reachable(states, initial, edges) if machine_class.strict? CompiledGraph.new( states: states.freeze, initial_state: initial, edges: deep_freeze_edges(edges), events: freeze_events(events), callbacks: freeze_callbacks ).freeze end |