diff options
Diffstat (limited to 'lib/blink/interface.rb')
-rw-r--r-- | lib/blink/interface.rb | 120 |
1 files changed, 71 insertions, 49 deletions
diff --git a/lib/blink/interface.rb b/lib/blink/interface.rb index 7e19c9798..660e9bd7d 100644 --- a/lib/blink/interface.rb +++ b/lib/blink/interface.rb @@ -23,6 +23,54 @@ module Blink # this is a bit of a hack, but it'll work for now attr_accessor :performoperation + attr_writer :noop + + #--------------------------------------------------------------- + # retrieve a named object + def Interface.[](name) + if @objects.has_key?(name) + return @objects[name] + else + raise "Object '#{name}' does not exist" + end + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- + # this is special, because it can be equivalent to running new + # this allows cool syntax like Blink::File["/etc/inetd.conf"] = ... + def Interface.[]=(name,object) + newobj = nil + if object.is_a?(Blink::Interface) + newobj = object + else + raise "must pass a Blink::Interface object" + end + + if @objects.has_key?(newobj.name) + puts @objects + raise "'#{newobj.name}' already exists in " + + "class '#{newobj.class}': #{@objects[newobj.name]}" + else + #Blink.debug("adding %s of type %s to class list" % + # [object.name,object.class]) + @objects[newobj.name] = newobj + end + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- + def Interface.has_key?(name) + return @objects.has_key?(name) + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- + # a left-recursive path again? + def change(ary) + + end + #--------------------------------------------------------------- #--------------------------------------------------------------- def evaluate @@ -39,25 +87,9 @@ module Blink #--------------------------------------------------------------- #--------------------------------------------------------------- - # set up the "interface" methods - [:sync,:retrieve].each { |method| - self.send(:define_method,method) { - self.each { |subobj| - #Blink.debug("sending '%s' to '%s'" % [method,subobj]) - subobj.send(method) - } - } - } - #--------------------------------------------------------------- - - #--------------------------------------------------------------- - def presync - self.each { |contained| - # this gets right to the heart of our question: - # do all subclasses of Interface contain all of their - # content in contained objects? - Blink::Modification.new(contained) - } + # return the full path to us, for logging and rollback + def fqpath + return self.class, self.name end #--------------------------------------------------------------- @@ -79,42 +111,32 @@ module Blink #--------------------------------------------------------------- #--------------------------------------------------------------- - # retrieve a named object - def Interface.[](name) - if @objects.has_key?(name) - return @objects[name] - else - raise "Object '#{name}' does not exist" - end - end + # should we actually do anything? + def noop + return self.noop || Blink[:noop] || false + end #--------------------------------------------------------------- #--------------------------------------------------------------- - # this is special, because it can be equivalent to running new - # this allows cool syntax like Blink::File["/etc/inetd.conf"] = ... - def Interface.[]=(name,object) - newobj = nil - if object.is_a?(Blink::Interface) - newobj = object - else - raise "must pass a Blink::Interface object" - end - - if @objects.has_key?(newobj.name) - puts @objects - raise "'#{newobj.name}' already exists in " + - "class '#{newobj.class}': #{@objects[newobj.name]}" - else - #Blink.debug("adding %s of type %s to class list" % - # [object.name,object.class]) - @objects[newobj.name] = newobj - end - end + # set up the "interface" methods + [:sync,:retrieve].each { |method| + self.send(:define_method,method) { + self.each { |subobj| + #Blink.debug("sending '%s' to '%s'" % [method,subobj]) + subobj.send(method) + } + } + } #--------------------------------------------------------------- #--------------------------------------------------------------- - def Interface.has_key?(name) - return @objects.has_key?(name) + def presync + self.each { |contained| + # this gets right to the heart of our question: + # do all subclasses of Interface contain all of their + # content in contained objects? + Blink::Modification.new(contained) + } end #--------------------------------------------------------------- end |