summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/state_machine.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-08-18 21:51:27 -0500
committerLuke Kanies <luke@madstop.com>2008-08-20 12:13:25 -0500
commit78bc32d0153dd98fadae99dcd71d26fc97210d3c (patch)
tree72fdd0d5ff938534e65a63bd83839df2ac1f6ddf /lib/puppet/util/state_machine.rb
parenta5ab52c628cae7ac9ed5ca1bd5de779944840802 (diff)
downloadpuppet-78bc32d0153dd98fadae99dcd71d26fc97210d3c.tar.gz
puppet-78bc32d0153dd98fadae99dcd71d26fc97210d3c.tar.xz
puppet-78bc32d0153dd98fadae99dcd71d26fc97210d3c.zip
Removing dead-end file work as promised.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet/util/state_machine.rb')
-rw-r--r--lib/puppet/util/state_machine.rb52
1 files changed, 0 insertions, 52 deletions
diff --git a/lib/puppet/util/state_machine.rb b/lib/puppet/util/state_machine.rb
deleted file mode 100644
index 9329df3ce..000000000
--- a/lib/puppet/util/state_machine.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-require 'puppet/util'
-
-# A simple class for defining simple state machines. You define
-# the state transitions, which translate to the states a given property
-# can be in and the methods used to transition between those states.
-#
-# == Example
-#
-# newproperty(:ensure) do
-#
-# :absent => :present (:create)
-#
-# statemachine.new(:create => {:absent => :present}, :destroy => {:present => :absent})
-#
-# mach.transition(:absent => :present).with :create
-# mach.transition(:present => :absent).with :destroy
-#
-# mach.transition :create => {:absent => :present}, :destroy => {:present => :absent}
-
-require 'puppet/simple_graph'
-require 'puppet/relationship'
-
-class Puppet::Util::StateMachine
- class Transition < Puppet::Relationship
- end
-
- def initialize(&block)
- @graph = Puppet::SimpleGraph.new
- @docs = {}
-
- instance_eval(&block) if block
- end
-
- # Define a state, with docs.
- def state(name, docs)
- @docs[name] = docs
- @graph.add_vertex(name)
- end
-
- # Check whether a state is defined.
- def state?(name)
- @graph.vertex?(name)
- end
-
- def transition(from, to)
- raise ArgumentError, "Unknown starting state %s" % from unless state?(from)
- raise ArgumentError, "Unknown ending state %s" % to unless state?(to)
- raise ArgumentError, "Transition %s => %s already exists" % [from, to] if @graph.edge?(from, to)
- transition = Transition.new(from, to)
- @graph.add_edge(transition)
- end
-end