Class: FiniteMachine::Definition
- Inherits:
-
Object
- Object
- FiniteMachine::Definition
- Defined in:
- lib/finite_machine/definition.rb
Overview
Responsible for defining a standalone state machine
Class Method Summary collapse
-
.add_deferred(deferred) ⇒ Array<Proc>
private
Add deferred.
-
.any_event ⇒ FiniteMachine::Const
The any event constant.
-
.any_state ⇒ FiniteMachine::Const
The any state constant.
-
.deferreds ⇒ Array<Proc>
private
The state machine deferreds.
-
.inherited(subclass) ⇒ void
private
Add deferred methods to the subclass.
-
.method_missing(method_name, *arguments, &block) ⇒ void
private
Delay lookup of DSL method.
-
.new(*args) ⇒ FiniteMachine::StateMachine
Initialize a StateMachine.
Class Method Details
.add_deferred(deferred) ⇒ Array<Proc>
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.
Add deferred
85 86 87 |
# File 'lib/finite_machine/definition.rb', line 85 def self.add_deferred(deferred) deferreds << deferred end |
.any_event ⇒ FiniteMachine::Const
The any event constant
16 17 18 |
# File 'lib/finite_machine/definition.rb', line 16 def self.any_event ANY_EVENT end |
.any_state ⇒ FiniteMachine::Const
The any state constant
31 32 33 |
# File 'lib/finite_machine/definition.rb', line 31 def self.any_state ANY_STATE end |
.deferreds ⇒ Array<Proc>
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.
The state machine deferreds
73 74 75 |
# File 'lib/finite_machine/definition.rb', line 73 def self.deferreds @deferreds ||= [] end |
.inherited(subclass) ⇒ void
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.
This method returns an undefined value.
Add deferred methods to the subclass
62 63 64 65 66 |
# File 'lib/finite_machine/definition.rb', line 62 def self.inherited(subclass) super deferreds.each { |d| subclass.add_deferred(d) } end |
.method_missing(method_name, *arguments, &block) ⇒ void
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.
This method returns an undefined value.
Delay lookup of DSL method
99 100 101 102 103 104 105 |
# File 'lib/finite_machine/definition.rb', line 99 def self.method_missing(method_name, *arguments, &block) deferred = proc do |name, args, blok, object| object.send(name, *args, &blok) end deferred = deferred.curry(4)[method_name][arguments][block] add_deferred(deferred) end |
.new(*args) ⇒ FiniteMachine::StateMachine
Initialize a StateMachine
47 48 49 50 51 52 |
# File 'lib/finite_machine/definition.rb', line 47 def self.new(*args) context = self FiniteMachine.new(*args) do context.deferreds.each { |d| d.call(self) } end end |