summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/autoload.rb
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
commit3180b9d9b2c844dade1d361326600f7001ec66dd (patch)
tree98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /lib/puppet/util/autoload.rb
parent543225970225de5697734bfaf0a6eee996802c04 (diff)
downloadpuppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
Diffstat (limited to 'lib/puppet/util/autoload.rb')
-rw-r--r--lib/puppet/util/autoload.rb250
1 files changed, 125 insertions, 125 deletions
diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb
index 21f99e4c0..c293ac14a 100644
--- a/lib/puppet/util/autoload.rb
+++ b/lib/puppet/util/autoload.rb
@@ -3,142 +3,142 @@ require 'puppet/util/cacher'
# Autoload paths, either based on names or all at once.
class Puppet::Util::Autoload
- require 'puppet/util/autoload/file_cache'
+ require 'puppet/util/autoload/file_cache'
- include Puppet::Util
- include Puppet::Util::Warnings
- include Puppet::Util::Cacher
- include Puppet::Util::Autoload::FileCache
+ include Puppet::Util
+ include Puppet::Util::Warnings
+ include Puppet::Util::Cacher
+ include Puppet::Util::Autoload::FileCache
- @autoloaders = {}
- @loaded = []
+ @autoloaders = {}
+ @loaded = []
- class << self
- attr_reader :autoloaders
- private :autoloaders
- end
-
- # Send [], []=, and :clear to the @autloaders hash
- Puppet::Util.classproxy self, :autoloaders, "[]", "[]="
+ class << self
+ attr_reader :autoloaders
+ private :autoloaders
+ end
- # List all loaded files.
- def self.list_loaded
- @loaded.sort { |a,b| a[0] <=> b[0] }.collect do |path, hash|
- "#{path}: #{hash[:file]}"
- end
- end
+ # Send [], []=, and :clear to the @autloaders hash
+ Puppet::Util.classproxy self, :autoloaders, "[]", "[]="
- # Has a given path been loaded? This is used for testing whether a
- # changed file should be loaded or just ignored. This is only
- # used in network/client/master, when downloading plugins, to
- # see if a given plugin is currently loaded and thus should be
- # reloaded.
- def self.loaded?(path)
- path = path.to_s.sub(/\.rb$/, '')
- @loaded.include?(path)
+ # List all loaded files.
+ def self.list_loaded
+ @loaded.sort { |a,b| a[0] <=> b[0] }.collect do |path, hash|
+ "#{path}: #{hash[:file]}"
end
-
- # Save the fact that a given path has been loaded. This is so
- # we can load downloaded plugins if they've already been loaded
- # into memory.
- def self.loaded(file)
- $" << file + ".rb" unless $".include?(file)
- @loaded << file unless @loaded.include?(file)
+ end
+
+ # Has a given path been loaded? This is used for testing whether a
+ # changed file should be loaded or just ignored. This is only
+ # used in network/client/master, when downloading plugins, to
+ # see if a given plugin is currently loaded and thus should be
+ # reloaded.
+ def self.loaded?(path)
+ path = path.to_s.sub(/\.rb$/, '')
+ @loaded.include?(path)
+ end
+
+ # Save the fact that a given path has been loaded. This is so
+ # we can load downloaded plugins if they've already been loaded
+ # into memory.
+ def self.loaded(file)
+ $" << file + ".rb" unless $".include?(file)
+ @loaded << file unless @loaded.include?(file)
+ end
+
+ attr_accessor :object, :path, :objwarn, :wrap
+
+ def initialize(obj, path, options = {})
+ @path = path.to_s
+ raise ArgumentError, "Autoload paths cannot be fully qualified" if @path !~ /^\w/
+ @object = obj
+
+ self.class[obj] = self
+
+ options.each do |opt, value|
+ opt = opt.intern if opt.is_a? String
+ begin
+ self.send(opt.to_s + "=", value)
+ rescue NoMethodError
+ raise ArgumentError, "#{opt} is not a valid option"
+ end
end
- attr_accessor :object, :path, :objwarn, :wrap
-
- def initialize(obj, path, options = {})
- @path = path.to_s
- raise ArgumentError, "Autoload paths cannot be fully qualified" if @path !~ /^\w/
- @object = obj
-
- self.class[obj] = self
-
- options.each do |opt, value|
- opt = opt.intern if opt.is_a? String
- begin
- self.send(opt.to_s + "=", value)
- rescue NoMethodError
- raise ArgumentError, "#{opt} is not a valid option"
- end
- end
-
- @wrap = true unless defined?(@wrap)
+ @wrap = true unless defined?(@wrap)
+ end
+
+ # Load a single plugin by name. We use 'load' here so we can reload a
+ # given plugin.
+ def load(name,env=nil)
+ path = name.to_s + ".rb"
+
+ searchpath(env).each do |dir|
+ file = File.join(dir, path)
+ next unless file_exist?(file)
+ begin
+ Kernel.load file, @wrap
+ name = symbolize(name)
+ loaded name, file
+ return true
+ rescue SystemExit,NoMemoryError
+ raise
+ rescue Exception => detail
+ puts detail.backtrace if Puppet[:trace]
+ raise Puppet::Error, "Could not autoload #{name}: #{detail}"
+ end
end
-
- # Load a single plugin by name. We use 'load' here so we can reload a
- # given plugin.
- def load(name,env=nil)
- path = name.to_s + ".rb"
-
- searchpath(env).each do |dir|
- file = File.join(dir, path)
- next unless file_exist?(file)
- begin
- Kernel.load file, @wrap
- name = symbolize(name)
- loaded name, file
- return true
- rescue SystemExit,NoMemoryError
- raise
- rescue Exception => detail
- puts detail.backtrace if Puppet[:trace]
- raise Puppet::Error, "Could not autoload #{name}: #{detail}"
- end
+ false
+ end
+
+ # Mark the named object as loaded. Note that this supports unqualified
+ # queries, while we store the result as a qualified query in the class.
+ def loaded(name, file)
+ self.class.loaded(File.join(@path, name.to_s))
+ end
+
+ # Indicate whether the specfied plugin has been loaded.
+ def loaded?(name)
+ self.class.loaded?(File.join(@path, name.to_s))
+ end
+
+ # Load all instances that we can. This uses require, rather than load,
+ # so that already-loaded files don't get reloaded unnecessarily.
+ def loadall
+ # Load every instance of everything we can find.
+ searchpath.each do |dir|
+ Dir.glob("#{dir}/*.rb").each do |file|
+ name = File.basename(file).sub(".rb", '').intern
+ next if loaded?(name)
+ begin
+ Kernel.require file
+ loaded(name, file)
+ rescue SystemExit,NoMemoryError
+ raise
+ rescue Exception => detail
+ puts detail.backtrace if Puppet[:trace]
+ raise Puppet::Error, "Could not autoload #{file}: #{detail}"
end
- false
+ end
end
-
- # Mark the named object as loaded. Note that this supports unqualified
- # queries, while we store the result as a qualified query in the class.
- def loaded(name, file)
- self.class.loaded(File.join(@path, name.to_s))
+ end
+
+ # The list of directories to search through for loadable plugins.
+ def searchpath(env=nil)
+ search_directories(env).collect { |d| File.join(d, @path) }.find_all { |d| FileTest.directory?(d) }
+ end
+
+ def module_directories(env=nil)
+ # We have to require this late in the process because otherwise we might have
+ # load order issues.
+ require 'puppet/node/environment'
+ Puppet::Node::Environment.new(env).modulepath.collect do |dir|
+ Dir.entries(dir).reject { |f| f =~ /^\./ }.collect { |f| File.join(dir, f) }
+ end.flatten.collect { |d| [File.join(d, "plugins"), File.join(d, "lib")] }.flatten.find_all do |d|
+ FileTest.directory?(d)
end
+ end
- # Indicate whether the specfied plugin has been loaded.
- def loaded?(name)
- self.class.loaded?(File.join(@path, name.to_s))
- end
-
- # Load all instances that we can. This uses require, rather than load,
- # so that already-loaded files don't get reloaded unnecessarily.
- def loadall
- # Load every instance of everything we can find.
- searchpath.each do |dir|
- Dir.glob("#{dir}/*.rb").each do |file|
- name = File.basename(file).sub(".rb", '').intern
- next if loaded?(name)
- begin
- Kernel.require file
- loaded(name, file)
- rescue SystemExit,NoMemoryError
- raise
- rescue Exception => detail
- puts detail.backtrace if Puppet[:trace]
- raise Puppet::Error, "Could not autoload #{file}: #{detail}"
- end
- end
- end
- end
-
- # The list of directories to search through for loadable plugins.
- def searchpath(env=nil)
- search_directories(env).collect { |d| File.join(d, @path) }.find_all { |d| FileTest.directory?(d) }
- end
-
- def module_directories(env=nil)
- # We have to require this late in the process because otherwise we might have
- # load order issues.
- require 'puppet/node/environment'
- Puppet::Node::Environment.new(env).modulepath.collect do |dir|
- Dir.entries(dir).reject { |f| f =~ /^\./ }.collect { |f| File.join(dir, f) }
- end.flatten.collect { |d| [File.join(d, "plugins"), File.join(d, "lib")] }.flatten.find_all do |d|
- FileTest.directory?(d)
- end
- end
-
- def search_directories(env=nil)
- [module_directories(env), Puppet[:libdir].split(File::PATH_SEPARATOR), $LOAD_PATH].flatten
- end
+ def search_directories(env=nil)
+ [module_directories(env), Puppet[:libdir].split(File::PATH_SEPARATOR), $LOAD_PATH].flatten
+ end
end