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.



23
24
25
26
# File 'lib/deltacloud/state_machine.rb', line 23

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



45
46
47
48
# File 'lib/deltacloud/state_machine.rb', line 45

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.



22
23
24
# File 'lib/deltacloud/state_machine.rb', line 22

def states
  @states
end

Instance Method Details

#finishObject



32
33
34
# File 'lib/deltacloud/state_machine.rb', line 32

def finish()
  state(:finish)
end

#startObject



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

def start()
  state(:start)
end

#state(name) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/deltacloud/state_machine.rb', line 36

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