Class: FiniteMachine::GenericDSL
- Inherits:
-
Object
- Object
- FiniteMachine::GenericDSL
- Defined in:
- lib/finite_machine/dsl.rb
Overview
A generic DSL for describing the state machine
Instance Method Summary collapse
-
#any_event ⇒ Object
Expose any event constant.
-
#any_state ⇒ Object
Expose any state constant.
-
#call(&block) ⇒ Object
private
Configure state machine properties.
-
#initialize(machine, attrs) ⇒ GenericDSL
constructor
Initialize a generic DSL.
-
#method_missing(method_name, *args, &block) ⇒ Object
private
Delegate attributes to machine instance.
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
private
Check if message can be handled by this DSL.
Constructor Details
#initialize(machine, attrs) ⇒ GenericDSL
Initialize a generic DSL
13 14 15 16 |
# File 'lib/finite_machine/dsl.rb', line 13 def initialize(machine, attrs) @machine = machine @attrs = attrs end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Delegate attributes to machine instance
33 34 35 36 37 38 39 |
# File 'lib/finite_machine/dsl.rb', line 33 def method_missing(method_name, *args, &block) if @machine.respond_to?(method_name) @machine.send(method_name, *args, &block) else super end end |
Instance Method Details
#any_event ⇒ Object
Expose any event constant
26 27 28 |
# File 'lib/finite_machine/dsl.rb', line 26 def any_event ANY_EVENT end |
#any_state ⇒ Object
Expose any state constant
20 21 22 |
# File 'lib/finite_machine/dsl.rb', line 20 def any_state ANY_STATE end |
#call(&block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Configure state machine properties
51 52 53 |
# File 'lib/finite_machine/dsl.rb', line 51 def call(&block) instance_eval(&block) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if message can be handled by this DSL
44 45 46 |
# File 'lib/finite_machine/dsl.rb', line 44 def respond_to_missing?(method_name, include_private = false) @machine.respond_to?(method_name) || super end |