Class: Deltacloud::StateMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/deltacloud/state_machine.rb

Defined Under Namespace

Classes: State, Transition

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ StateMachine

Returns a new instance of StateMachine.



6
7
8
9
# File 'lib/deltacloud/state_machine.rb', line 6

def initialize(&block)
  @states  = []
  instance_eval &block if block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



28
29
30
31
# File 'lib/deltacloud/state_machine.rb', line 28

def method_missing(sym,*args)
  return state( sym ) if ( args.empty? )
  super( sym, *args )
end

Instance Attribute Details

#statesObject (readonly)

Returns the value of attribute states.



5
6
7
# File 'lib/deltacloud/state_machine.rb', line 5

def states
  @states
end

Instance Method Details

#finishObject



15
16
17
# File 'lib/deltacloud/state_machine.rb', line 15

def finish()
  state(:finish)
end

#startObject



11
12
13
# File 'lib/deltacloud/state_machine.rb', line 11

def start()
  state(:start)
end

#state(name) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/deltacloud/state_machine.rb', line 19

def state(name)
  state = @states.find{|e| e.name == name.to_sym}
  if ( state.nil? )
    state = State.new( self, name.to_sym )
    @states << state
  end
  state
end