Class: Deltacloud::StateMachine::State

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine, name) ⇒ State

Returns a new instance of State.



67
68
69
70
71
# File 'lib/deltacloud/models/state_machine.rb', line 67

def initialize(machine, name)
  @machine = machine
  @name    = name
  @transitions = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



64
65
66
# File 'lib/deltacloud/models/state_machine.rb', line 64

def name
  @name
end

#transitionsObject (readonly)

Returns the value of attribute transitions.



65
66
67
# File 'lib/deltacloud/models/state_machine.rb', line 65

def transitions
  @transitions
end

Instance Method Details

#from(*states) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/deltacloud/models/state_machine.rb', line 84

def from(*states)
  states.each do |s|
    initial = @machine.state(s)
    trans = initial.to self.name
    trans.automatically
  end
end

#to(destination_name) ⇒ Object



77
78
79
80
81
82
# File 'lib/deltacloud/models/state_machine.rb', line 77

def to(destination_name)
  destination = @machine.state(destination_name)
  transition = Transition.new( @machine, destination )
  @transitions << transition
  transition
end

#to_sObject



73
74
75
# File 'lib/deltacloud/models/state_machine.rb', line 73

def to_s
  self.name.to_s
end