diff options
-rw-r--r-- | lib/blink/component.rb | 33 | ||||
-rw-r--r-- | lib/blink/type.rb | 10 | ||||
-rw-r--r-- | lib/blink/type/filetype.rb | 22 | ||||
-rw-r--r-- | test/types/tc_filetype.rb | 15 |
4 files changed, 52 insertions, 28 deletions
diff --git a/lib/blink/component.rb b/lib/blink/component.rb index 35a8d83d9..62481f000 100644 --- a/lib/blink/component.rb +++ b/lib/blink/component.rb @@ -11,7 +11,17 @@ module Blink class Component < Blink::Type attr_accessor :name - @objects = Hash.new(nil) + @name = :component + @namevar = :name + @params = [ + :name + ] + + #--------------------------------------------------------------- + def [](object) + @subobjects[object] + end + #--------------------------------------------------------------- #--------------------------------------------------------------- # our components are effectively arrays, with a bit extra functionality @@ -23,16 +33,19 @@ module Blink #--------------------------------------------------------------- #--------------------------------------------------------------- - def initialize(*args) - args = Hash[*args] + def initialize(hash) + #super(hash) + begin + @name = hash[:name] + rescue + fail TypeError.new("Components must be provided a name") + end - unless args.include?(:name) + unless @name fail TypeError.new("Components must be provided a name") - else - self.name = args[:name] end - Component[self.name] = self + self.class[self.name] = self @subobjects = [] end @@ -47,9 +60,9 @@ module Blink #--------------------------------------------------------------- #--------------------------------------------------------------- - def to_s - return self.name - end + #def to_s + # return self.name + #end #--------------------------------------------------------------- end end diff --git a/lib/blink/type.rb b/lib/blink/type.rb index dc23161b8..26b69f669 100644 --- a/lib/blink/type.rb +++ b/lib/blink/type.rb @@ -3,6 +3,7 @@ # $Id$ # included so we can test object types +require 'blink' require 'blink/type/state' @@ -68,8 +69,8 @@ module Blink @@typeary.each { |otype| if @@typehash.include?(otype.name) if @@typehash[otype.name] != otype - Blink.warning("Object type %s is already defined" % - otype.name) + Blink.warning("Object type %s is already defined (%s vs %s)" % + [otype.name,@@typehash[otype.name],otype]) end else @@typehash[otype.name] = otype @@ -90,6 +91,7 @@ module Blink def Type.inherited(sub) sub.initvars + Blink.debug("subtype %s just created" % sub) # add it to the master list # unfortunately we can't yet call sub.name, because the #inherited # method gets called before any commands in the class definition @@ -117,6 +119,7 @@ module Blink #--------------------------------------------------------------- def Type.newtype(type) + raise "Type.newtype called, but I don't know why" @@typeary.push(type) if @@typehash.has_key?(type.name) Blink.notice("Redefining object type %s" % type.name) @@ -147,6 +150,7 @@ module Blink if @objects.has_key?(name) return @objects[name] else + p @objects raise "Object '#{name}' does not exist" end end @@ -302,7 +306,7 @@ module Blink } # add this object to the specific class's list of objects - self.class[name] = self + self.class[self.name] = self # and then add it to the master list Blink::Type.push(self) diff --git a/lib/blink/type/filetype.rb b/lib/blink/type/filetype.rb index b97ac1b07..d3a715c7a 100644 --- a/lib/blink/type/filetype.rb +++ b/lib/blink/type/filetype.rb @@ -11,6 +11,9 @@ module Blink class FileType < Blink::Type include Enumerable + @namevar = :notused + @name = :filetype + attr_accessor :file, :splitchar, :childtype @@classes = Hash.new(nil) @@ -34,12 +37,24 @@ module Blink #--------------------------------------------------------------- #--------------------------------------------------------------- + def FileType.name + return @name + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- def FileType.name=(name) @name = name end #--------------------------------------------------------------- #--------------------------------------------------------------- + def FileType.namevar + return :notused + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- def FileType.regex return @regex end @@ -95,7 +110,7 @@ module Blink # now create the record type klass.childtype = Blink::FileRecord.newtype( - :name => arghash[:name], + :name => arghash[:name] + "_record", :splitchar => arghash[:recordsplit], :fields => arghash[:fields], :namevar => arghash[:namevar] @@ -103,7 +118,7 @@ module Blink klass.splitchar = arghash[:linesplit] klass.name = arghash[:name] - Blink.debug("adding class %s" % arghash[:name]) + Blink.debug("adding class %s as a subclass of %s" % [arghash[:name],self]) @@classes[arghash[:name]] = klass return klass @@ -261,6 +276,9 @@ module Blink class FileRecord < Blink::Type attr_accessor :fields, :namevar, :splitchar, :object + @namevar = :notused + @name = :filerecord + @@subclasses = {} #--------------------------------------------------------------- diff --git a/test/types/tc_filetype.rb b/test/types/tc_filetype.rb index bf2e2ee9d..59d5eb946 100644 --- a/test/types/tc_filetype.rb +++ b/test/types/tc_filetype.rb @@ -5,6 +5,7 @@ if __FILE__ == $0 end require 'blink' +require 'blink/type' require 'blink/type/filetype' require 'test/unit' @@ -25,18 +26,6 @@ class TestFileType < Test::Unit::TestCase ) } end - - @passwdtype = Blink::FileType["passwd"] - if @passwdtype.nil? - assert_nothing_raised() { - @passwdtype = Blink::FileType.newtype( - :name => "user", - :recordsplit => ":", - :fields => %w{name password uid gid gcos home shell}, - :namevar => "name" - ) - } - end end def test_passwd1_nochange @@ -110,6 +99,6 @@ class TestFileType < Test::Unit::TestCase assert(file.insync?) - #Kernel.system("rm /tmp/oparsepasswd") + Kernel.system("rm /tmp/oparsepasswd") end end |