Class: Stateflow::State

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (State) initialize(name, &options)

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

- (Object) name

Returns the value of attribute name



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

def name
  @name
end

- (Object) options

Returns the value of attribute options



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

def options
  @options
end

Instance Method Details

- (Object) enter(method = nil, &block)



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

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

- (Object) execute_action(action, base)



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

- (Object) exit(method = nil, &block)



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

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