summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/config.rb49
-rw-r--r--lib/puppet/type.rb1
2 files changed, 50 insertions, 0 deletions
diff --git a/lib/puppet/config.rb b/lib/puppet/config.rb
new file mode 100644
index 000000000..dc8b05f56
--- /dev/null
+++ b/lib/puppet/config.rb
@@ -0,0 +1,49 @@
+module Puppet # :nodoc:
+# The class for handling configuration files.
+class Config < Hash
+ # Slight override, since we can't seem to have a subclass where all instances
+ # have the same default block.
+ def [](section)
+ unless self.has_key?(section)
+ self[section] = {}
+ end
+ super
+ end
+
+ def initialize(file)
+ text = nil
+
+ begin
+ text = File.read(file)
+ rescue Errno::ENOENT
+ raise Puppet::Error, "No such file %s" % file
+ rescue Errno::EACCES
+ raise Puppet::Error, "Permission denied to file %s" % file
+ end
+
+ # Store it for later, in a way that we can test and such.
+ @file = Puppet::ParsedFile.new(file)
+
+ @values = Hash.new { |names, name|
+ names[name] = {}
+ }
+
+ section = "puppet"
+ text.split(/\n/).each { |line|
+ case line
+ when /^\[(\w+)\]$/: section = $1 # Section names
+ when /^\s*#/: next # Skip comments
+ when /^\s*$/: next # Skip blanks
+ when /^\s*(\w+)\s+(.+)$/: # settings
+ var = $1
+ value = $2
+ self[section][var] = value
+ else
+ raise Puppet::Error, "Could not match line %s" % line
+ end
+ }
+ end
+end
+end
+
+# $Id$
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 0735d3945..73963d2aa 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -815,6 +815,7 @@ class Type < Puppet::Element
# and such. This allows for two specifications of the same object and
# the same values, but it's pretty limited right now. The result of merging
# states is very different from the result of merging parameters or metaparams.
+ # This is currently unused.
def merge(hash)
hash.each { |param, value|
if param.is_a?(String)