Class: Stateflow::State

Inherits:
Object
  • Object
show all
Defined in:
lib/stateflow/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &options) ⇒ State

Returns a new instance of State.



5
6
7
8
9
10
# File 'lib/stateflow/state.rb', line 5

def initialize(name, &options)
  @name = name
  @options = Hash.new
  
  instance_eval(&options) if block_given?
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/stateflow/state.rb', line 3

def name
  @name
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/stateflow/state.rb', line 3

def options
  @options
end

Instance Method Details

#enter(method = nil, &block) ⇒ Object



12
13
14
# File 'lib/stateflow/state.rb', line 12

def enter(method = nil, &block)
  @options[:enter] = method.nil? ? block : method
end

#execute_action(action, base) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/stateflow/state.rb', line 20

def execute_action(action, base)
  action = @options[action.to_sym]
  
  case action
  when Symbol, String
    base.send(action)
  when Proc
    action.call(base)
  end
end

#exit(method = nil, &block) ⇒ Object



16
17
18
# File 'lib/stateflow/state.rb', line 16

def exit(method = nil, &block)
  @options[:exit] = method.nil? ? block : method
end