summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-04-19 00:09:19 +0000
committerLuke Kanies <luke@madstop.com>2005-04-19 00:09:19 +0000
commit7deba97509ec91885d76e0d909287a7553c995d8 (patch)
treee563ce732c10c511535ab81d5570bfbe2b162d4d
parentb18d071b60d3529466bd1c568c3b14b23054c7a9 (diff)
downloadpuppet-7deba97509ec91885d76e0d909287a7553c995d8.tar.gz
puppet-7deba97509ec91885d76e0d909287a7553c995d8.tar.xz
puppet-7deba97509ec91885d76e0d909287a7553c995d8.zip
adding typegenerator baseclass
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@191 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/blink/type/typegen.rb97
1 files changed, 97 insertions, 0 deletions
diff --git a/lib/blink/type/typegen.rb b/lib/blink/type/typegen.rb
new file mode 100644
index 000000000..afca0afea
--- /dev/null
+++ b/lib/blink/type/typegen.rb
@@ -0,0 +1,97 @@
+#!/usr/local/bin/ruby -w
+
+# $Id$
+
+# parse and write configuration files using objects with minimal parsing abilities
+
+require 'etc'
+require 'blink/type'
+
+module Blink
+ class TypeGenerator < Blink::Type
+ include Enumerable
+
+ @namevar = :notused
+ @name = :typegen
+
+ attr_accessor :childtype
+
+ @@subclasses = Hash.new(nil)
+
+ #---------------------------------------------------------------
+ def TypeGenerator.[](name)
+ return @@classes[name]
+ end
+ #---------------------------------------------------------------
+
+ #---------------------------------------------------------------
+ def TypeGenerator.childtype=(childtype)
+ @childtype = childtype
+ end
+ #---------------------------------------------------------------
+
+ #---------------------------------------------------------------
+ def TypeGenerator.childtype
+ return @childtype
+ end
+ #---------------------------------------------------------------
+
+ #---------------------------------------------------------------
+ def TypeGenerator.name
+ return @name
+ end
+ #---------------------------------------------------------------
+
+ #---------------------------------------------------------------
+ def TypeGenerator.name=(name)
+ @name = name
+ end
+ #---------------------------------------------------------------
+
+ #---------------------------------------------------------------
+ def TypeGenerator.namevar
+ return :notused
+ end
+ #---------------------------------------------------------------
+
+ #---------------------------------------------------------------
+ def TypeGenerator.newtype(arghash)
+ unless defined? @options
+ raise "Type %s is set up incorrectly" % self
+ end
+
+ arghash.each { |key,value|
+ unless options.include?(key)
+ raise "Invalid argument %s on class %s" %
+ [key,self]
+ end
+ }
+ options.each { |option|
+ unless arghash.include?(option)
+ raise "Must pass %s to class %s" %
+ [option,self.class.to_s]
+ end
+ }
+
+ if @@subclasses.include?(arghash[:name])
+ raise "File type %s already exists" % arghash[:name]
+ end
+
+ klassname = arghash[:name].capitalize
+
+ # create the file type
+ module_eval "
+ class %s < TypeGenerator
+ end" % klassname
+ klass = eval(klassname)
+ klass.name = arghash[:name]
+
+ Blink.debug("adding class %s as a subclass of %s" % [arghash[:name],self])
+ @@subclasses[arghash[:name]] = klass
+
+ return klass
+ end
+ #---------------------------------------------------------------
+ end
+ #---------------------------------------------------------------
+end