Class: FiniteMachine::GenericDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/finite_machine/dsl.rb

Overview

A generic DSL for describing the state machine

Direct Known Subclasses

DSL, Observer

Instance Method Summary collapse

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_eventObject

Expose any event constant



26
27
28
# File 'lib/finite_machine/dsl.rb', line 26

def any_event
  ANY_EVENT
end

#any_stateObject

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

Returns:

  • (Boolean)


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