diff options
author | Luke Kanies <luke@madstop.com> | 2005-04-21 15:46:01 +0000 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2005-04-21 15:46:01 +0000 |
commit | cf08be12cc1418b02feb0ae52a54de265e440ea6 (patch) | |
tree | e1a2d4f65d1e45a75c508e96b6d36477f8e83198 /lib/blink/elements.rb | |
parent | b6d0f0cd4dacc1f8ef9fb22f98e191082fbcb6d5 (diff) | |
download | puppet-cf08be12cc1418b02feb0ae52a54de265e440ea6.tar.gz puppet-cf08be12cc1418b02feb0ae52a54de265e440ea6.tar.xz puppet-cf08be12cc1418b02feb0ae52a54de265e440ea6.zip |
renaming statetree to elements
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@201 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/blink/elements.rb')
-rw-r--r-- | lib/blink/elements.rb | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/lib/blink/elements.rb b/lib/blink/elements.rb new file mode 100644 index 000000000..64fac9b24 --- /dev/null +++ b/lib/blink/elements.rb @@ -0,0 +1,109 @@ +#!/usr/local/bin/ruby -w + +# $Id$ + +# the definition of our state tree +# the base class for both leaves and branches, and the base class for each +# of them, also + +require 'blink' +require 'blink/statechange' + +#--------------------------------------------------------------- +class Blink::Element + attr_accessor :noop + + #--------------------------------------------------------------- + @@interface_methods = [ + :retrieve, :insync?, :sync, :fqpath, :evaluate, :refresh + ] + + @@interface_methods.each { |method| + self.send(:define_method,method) { + raise "%s has not overridden %s" % [self.class,method] + } + } + + class Blink::Element::Branch + attr_accessor :children, :parent, :states + + #--------------------------------------------------------------- + # iterate across all children, and then iterate across states + # we do children first so we're sure that all dependent objects + # are checked first + def each + [@children,@states].each { |child| + yield child + } + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- + # this method is responsible for collecting state changes + # we always descend into the children before we evaluate our current + # states + def evaluate(transaction) + self.each { |child| child.evaluate } + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- + def initialize + @childary = [] + @childhash = {} + @states = [] + @parent = nil + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- + # this method is responsible for handling changes in dependencies + # for instance, restarting a service if a config file is changed + # in general, we just hand the method up to our parent, but for + # objects that might need to refresh, they'll override this method + # XXX at this point, if all dependent objects change, then this method + # might get called for each change + def refresh(transaction) + unless @parent.nil? + @parent.refresh(transaction) + end + end + #--------------------------------------------------------------- + end + + #--------------------------------------------------------------- + class Blink::Element::Leaf + attr_accessor :is, :should, :parent + + #--------------------------------------------------------------- + # this assumes the controlling process will actually execute the change + # which will demonstrably not work with states that are part of a larger + # whole, like FileRecordStates + def evaluate(transaction) + self.retrieve + transaction.change(Blink::StateChange.new(state)) unless self.insync? + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- + def initialize + @is = nil + @should = nil + @parent = nil + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- + def refresh(transaction) + self.retrieve + + # we definitely need some way to batch these refreshes, so a + # given object doesn't get refreshed multiple times in a single + # run + @parent.refresh + end + #--------------------------------------------------------------- + end + #--------------------------------------------------------------- +end +#--------------------------------------------------------------- |