diff options
| author | Luke Kanies <luke@madstop.com> | 2005-04-19 15:44:39 +0000 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2005-04-19 15:44:39 +0000 |
| commit | 737876563918bd7d3f48cc60e56efcbe79173368 (patch) | |
| tree | 7c390fe4e52612bf50c7a50dccdb5c50c393b71c /lib | |
| parent | 490854a2edf381c34083f0049e4c7ea3f1a20ad0 (diff) | |
| download | puppet-737876563918bd7d3f48cc60e56efcbe79173368.tar.gz puppet-737876563918bd7d3f48cc60e56efcbe79173368.tar.xz puppet-737876563918bd7d3f48cc60e56efcbe79173368.zip | |
completed the first step to enabling multiple record types in filetypes
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@195 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/blink/type/typegen/filerecord.rb | 37 | ||||
| -rw-r--r-- | lib/blink/type/typegen/filetype.rb | 45 |
2 files changed, 63 insertions, 19 deletions
diff --git a/lib/blink/type/typegen/filerecord.rb b/lib/blink/type/typegen/filerecord.rb index 4b610f58b..a60bf01b8 100644 --- a/lib/blink/type/typegen/filerecord.rb +++ b/lib/blink/type/typegen/filerecord.rb @@ -12,16 +12,19 @@ require 'blink/type/typegen' class Blink::Type::FileRecord < Blink::Type::TypeGenerator attr_accessor :fields, :namevar, :splitchar, :object - @options = [:name, :splitchar, :fields, :namevar] + @options = [:name, :splitchar, :fields, :namevar, :filetype] @abstract = true @name = :filerecord #--------------------------------------------------------------- - #def FileRecord.newtype(hash) - # klass = super(hash) - # return klass - #end + def FileRecord.newtype(hash) + shortname = hash[:name] + hash[:name] = hash[:filetype].name.capitalize + hash[:name].capitalize + klass = super(hash) + klass.name = shortname + return klass + end #--------------------------------------------------------------- #--------------------------------------------------------------- @@ -37,6 +40,30 @@ class Blink::Type::FileRecord < Blink::Type::TypeGenerator #--------------------------------------------------------------- #--------------------------------------------------------------- + def FileRecord.filetype + @filetype + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- + def FileRecord.filetype=(filetype) + @filetype = filetype + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- + def FileRecord.match(object,line) + if @regex.match(line) + child = self.new(object) + child.record = line + return child + else + return nil + end + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- def FileRecord.namevar=(field) @namevar = field end diff --git a/lib/blink/type/typegen/filetype.rb b/lib/blink/type/typegen/filetype.rb index c83796e0f..80530aaea 100644 --- a/lib/blink/type/typegen/filetype.rb +++ b/lib/blink/type/typegen/filetype.rb @@ -10,7 +10,7 @@ require 'blink/type/typegen' class Blink::Type::FileType < Blink::Type::TypeGenerator attr_accessor :childtype - @options = [:name, :linesplit, :recordsplit, :fields, :namevar] + @options = [:name, :linesplit] @abstract = true @name = :filetype @@ -22,12 +22,12 @@ class Blink::Type::FileType < Blink::Type::TypeGenerator end klass = super(hash) - klass.childtype = Blink::Type::FileRecord.newtype( - :name => hash[:name] + "_record", - :splitchar => hash[:recordsplit], - :fields => hash[:fields], - :namevar => hash[:namevar] - ) + #klass.childtype = Blink::Type::FileRecord.newtype( + # :name => hash[:name] + "_record", + # :splitchar => hash[:recordsplit], + # :fields => hash[:fields], + # :namevar => hash[:namevar] + #) #klass.addrecord( # :name => hash[:name] + "_record", # :splitchar => hash[:recordsplit], @@ -45,7 +45,15 @@ class Blink::Type::FileType < Blink::Type::TypeGenerator unless defined? @records @records = {} end - @records[hash[:name]] = Blink::Type::FileRecord.newtype(hash) + hash[:filetype] = self + recordtype = Blink::Type::FileRecord.newtype(hash) + @records[recordtype.name] = recordtype + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- + def FileType.records + return @records end #--------------------------------------------------------------- @@ -119,8 +127,8 @@ class Blink::Type::FileType < Blink::Type::TypeGenerator #--------------------------------------------------------------- # create a new record with a block - def add(&block) - obj = self.class.childtype.new(self,&block) + def add(type,&block) + obj = self.class.records[type].new(self,&block) Blink.debug("adding %s" % obj.name) @childary.push(obj) @childhash[obj.name] = obj @@ -191,11 +199,20 @@ class Blink::Type::FileType < Blink::Type::TypeGenerator } } - @childary = str.split(self.class.regex).collect { |record| - child = self.class.childtype.new(self) - child.record = record + @childary = str.split(self.class.regex).collect { |line| + childobj = self.class.records.each { |name,recordtype| + if child = recordtype.match(self,line) + break child + end + } + #child = self.class.childtype.new(self) + #child.record = record #puts "adding child %s" % child.name - child + if childobj.nil? + Blink.warning("%s: could not match %s" % [self.name,line]) + next + end + childobj } @childary.each { |child| |
