diff options
author | Luke Kanies <luke@puppetlabs.com> | 2010-07-07 23:34:10 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-07-09 12:31:45 -0700 |
commit | 3c0059195fb2b1255f368d98021f4a99ecd121a6 (patch) | |
tree | ee22c31b02f14d267a24acce875f3f185fb16617 /lib | |
parent | cea2e5b3fe03de8ef56a97af25ef8b6dd7eb3d7d (diff) | |
download | puppet-3c0059195fb2b1255f368d98021f4a99ecd121a6.tar.gz puppet-3c0059195fb2b1255f368d98021f4a99ecd121a6.tar.xz puppet-3c0059195fb2b1255f368d98021f4a99ecd121a6.zip |
Fix for #4178 - generalize autoloading to include .rb
This mostly modifies autoloading to look for files ending in either 'pp' or
'rb' using Dir globing with {,.pp,.rb} or .{pp,rb} as appropriate. It could
easily be extended to add support for other formats (e.g. xml) by adding them
to the globs (though, if this were to be done often, having a centralized list
of supported extensions would be a good (and easy) refactor).
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/dsl/resource_api.rb | 2 | ||||
-rw-r--r-- | lib/puppet/module.rb | 20 | ||||
-rw-r--r-- | lib/puppet/parser/files.rb | 6 | ||||
-rw-r--r-- | lib/puppet/resource.rb | 15 |
4 files changed, 13 insertions, 30 deletions
diff --git a/lib/puppet/dsl/resource_api.rb b/lib/puppet/dsl/resource_api.rb index 98e52158b..5556eb864 100644 --- a/lib/puppet/dsl/resource_api.rb +++ b/lib/puppet/dsl/resource_api.rb @@ -44,6 +44,8 @@ class Puppet::DSL::ResourceAPI resource.eachparam do |param| instance_variable_set("@#{param.name}", param.value) end + @title = resource.title + @name ||= resource.title end def create_resource(type, names, arguments = nil) diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb index 1ea3df058..995262ddf 100644 --- a/lib/puppet/module.rb +++ b/lib/puppet/module.rb @@ -121,17 +121,12 @@ class Puppet::Module end # Return the list of manifests matching the given glob pattern, - # defaulting to 'init.pp' for empty modules. + # defaulting to 'init.{pp,rb}' for empty modules. def match_manifests(rest) - return find_init_manifest unless rest # Use init.pp - - rest ||= "init.pp" - full_path = File::join(path, MANIFESTS, rest) - result = Dir.glob(full_path).reject { |f| FileTest.directory?(f) } - if result.size == 0 and rest !~ /\.pp$/ - result = Dir.glob(full_path + ".pp") - end - result.flatten.compact + pat = File.join(path, MANIFESTS, rest || 'init') + Dir. + glob(pat + (File.extname(pat).empty? ? '.{pp,rb}' : '')). + reject { |f| FileTest.directory?(f) } end def metadata_file @@ -190,11 +185,6 @@ class Puppet::Module private - def find_init_manifest - return [] unless file = manifest("init.pp") - return [file] - end - def subpath(type) return File.join(path, type) unless type.to_s == "plugins" diff --git a/lib/puppet/parser/files.rb b/lib/puppet/parser/files.rb index 37a726524..aad74699f 100644 --- a/lib/puppet/parser/files.rb +++ b/lib/puppet/parser/files.rb @@ -24,11 +24,7 @@ module Puppet::Parser::Files # Than that would be a "no." end abspat = File::expand_path(start, cwd) - files = Dir.glob(abspat).reject { |f| FileTest.directory?(f) } - if files.size == 0 - files = Dir.glob(abspat + ".pp").reject { |f| FileTest.directory?(f) } - end - return [nil, files] + return [nil, Dir.glob(abspat + (File.extname(abspat).empty? ? '{,.pp,.rb}' : '' )).reject { |f| FileTest.directory?(f) }] end # Find the concrete file denoted by +file+. If +file+ is absolute, diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb index 393211e09..3b96e7e99 100644 --- a/lib/puppet/resource.rb +++ b/lib/puppet/resource.rb @@ -351,7 +351,8 @@ class Puppet::Resource end def find_resource_type(type) - find_builtin_resource_type(type) || find_defined_resource_type(type) + # It still works fine without the type == 'class' short-cut, but it is a lot slower. + find_builtin_resource_type(type) || find_defined_resource_type(type) unless type.to_s.downcase == 'class' end def find_builtin_resource_type(type) @@ -432,18 +433,12 @@ class Puppet::Resource end def resolve_type - type = munge_type_name(@unresolved_type) - - case type + case type = munge_type_name(@unresolved_type) when "Class", "Node"; - return type + type else # Otherwise, some kind of builtin or defined resource type - return munge_type_name(if r = find_resource_type(type) - r.name - else - type - end) + munge_type_name( (r = find_resource_type(type)) ? r.name : type) end end |