diff options
author | Luke Kanies <luke@madstop.com> | 2009-06-04 00:32:12 -0500 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-07-05 18:47:08 +1000 |
commit | fc1f8cdbee606da0d2a1a162942295d28cdcbf64 (patch) | |
tree | de5a811593d2b5d43544ca1ed8eb850e3de094eb /lib/puppet/parser | |
parent | 325b8e4f6f21341d0c8d04297b019db47af2abc6 (diff) | |
download | puppet-fc1f8cdbee606da0d2a1a162942295d28cdcbf64.tar.gz puppet-fc1f8cdbee606da0d2a1a162942295d28cdcbf64.tar.xz puppet-fc1f8cdbee606da0d2a1a162942295d28cdcbf64.zip |
Adding a special class to handle loaded classes/defines/nodes
This class is extracted from the Parser class,
and the main driver for it is to enable us to put mutexes
around some of the hashes to see if they're the source
of a race condition.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r-- | lib/puppet/parser/loaded_code.rb | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/lib/puppet/parser/loaded_code.rb b/lib/puppet/parser/loaded_code.rb new file mode 100644 index 000000000..7c918d4c3 --- /dev/null +++ b/lib/puppet/parser/loaded_code.rb @@ -0,0 +1,85 @@ +class Puppet::Parser::LoadedCode + def initialize + @hostclasses = {} + @definitions = {} + @nodes = {} + end + + def add_hostclass(name, code) + @hostclasses[munge_name(name)] = code + end + + def hostclass(name) + @hostclasses[munge_name(name)] + end + + def add_node(name, code) + @nodes[munge_name(name)] = code + end + + def node(name) + @nodes[munge_name(name)] + end + + def nodes? + @nodes.length > 0 + end + + def add_definition(name, code) + @definitions[munge_name(name)] = code + end + + def definition(name) + @definitions[munge_name(name)] + end + + def find(namespace, name, type) + if r = find_fully_qualified(name, type) + return r + end + + ary = namespace.split("::") + + while ary.length > 0 + tmp_namespace = ary.join("::") + if r = find_partially_qualified(tmp_namespace, name, type) + return r + end + + # Delete the second to last object, which reduces our namespace by one. + ary.pop + end + + send(type, name) + end + + def find_node(name) + find("", name, :node) + end + + def find_hostclass(namespace, name) + find(namespace, name, :hostclass) + end + + def find_definition(namespace, name) + find(namespace, name, :definition) + end + + private + + def find_fully_qualified(name, type) + return nil unless name =~ /^::/ + + name = name.sub(/^::/, '') + + send(type, name) + end + + def find_partially_qualified(namespace, name, type) + send(type, [namespace, name].join("::")) + end + + def munge_name(name) + name.to_s.downcase + end +end |