summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/feature.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/util/feature.rb')
-rw-r--r--lib/puppet/util/feature.rb124
1 files changed, 62 insertions, 62 deletions
diff --git a/lib/puppet/util/feature.rb b/lib/puppet/util/feature.rb
index 99587a06b..2f704104a 100644
--- a/lib/puppet/util/feature.rb
+++ b/lib/puppet/util/feature.rb
@@ -2,83 +2,83 @@
# Copyright (c) 2006. All rights reserved.
class Puppet::Util::Feature
- attr_reader :path
+ attr_reader :path
- # Create a new feature test. You have to pass the feature name,
- # and it must be unique. You can either provide a block that
- # will get executed immediately to determine if the feature
- # is present, or you can pass an option to determine it.
- # Currently, the only supported option is 'libs' (must be
- # passed as a symbol), which will make sure that each lib loads
- # successfully.
- def add(name, options = {})
- method = name.to_s + "?"
- raise ArgumentError, "Feature #{name} is already defined" if self.class.respond_to?(method)
+ # Create a new feature test. You have to pass the feature name,
+ # and it must be unique. You can either provide a block that
+ # will get executed immediately to determine if the feature
+ # is present, or you can pass an option to determine it.
+ # Currently, the only supported option is 'libs' (must be
+ # passed as a symbol), which will make sure that each lib loads
+ # successfully.
+ def add(name, options = {})
+ method = name.to_s + "?"
+ raise ArgumentError, "Feature #{name} is already defined" if self.class.respond_to?(method)
- if block_given?
- begin
- result = yield
- rescue Exception => detail
- warn "Failed to load feature test for #{name}: #{detail}"
- result = false
- end
- @results[name] = result
- end
-
- meta_def(method) do
- @results[name] = test(name, options) unless @results.include?(name)
- @results[name]
- end
+ if block_given?
+ begin
+ result = yield
+ rescue Exception => detail
+ warn "Failed to load feature test for #{name}: #{detail}"
+ result = false
+ end
+ @results[name] = result
end
- # Create a new feature collection.
- def initialize(path)
- @path = path
- @results = {}
- @loader = Puppet::Util::Autoload.new(self, @path)
+ meta_def(method) do
+ @results[name] = test(name, options) unless @results.include?(name)
+ @results[name]
end
+ end
- def load
- @loader.loadall
- end
+ # Create a new feature collection.
+ def initialize(path)
+ @path = path
+ @results = {}
+ @loader = Puppet::Util::Autoload.new(self, @path)
+ end
- def method_missing(method, *args)
- return super unless method.to_s =~ /\?$/
+ def load
+ @loader.loadall
+ end
- feature = method.to_s.sub(/\?$/, '')
- @loader.load(feature)
+ def method_missing(method, *args)
+ return super unless method.to_s =~ /\?$/
- respond_to?(method) && self.send(method)
- end
+ feature = method.to_s.sub(/\?$/, '')
+ @loader.load(feature)
- # Actually test whether the feature is present. We only want to test when
- # someone asks for the feature, so we don't unnecessarily load
- # files.
- def test(name, options)
- return true unless ary = options[:libs]
- ary = [ary] unless ary.is_a?(Array)
+ respond_to?(method) && self.send(method)
+ end
- ary.each do |lib|
- return false unless load_library(lib, name)
- end
+ # Actually test whether the feature is present. We only want to test when
+ # someone asks for the feature, so we don't unnecessarily load
+ # files.
+ def test(name, options)
+ return true unless ary = options[:libs]
+ ary = [ary] unless ary.is_a?(Array)
- # We loaded all of the required libraries
- true
+ ary.each do |lib|
+ return false unless load_library(lib, name)
end
- private
+ # We loaded all of the required libraries
+ true
+ end
+
+ private
- def load_library(lib, name)
- raise ArgumentError, "Libraries must be passed as strings not #{lib.class}" unless lib.is_a?(String)
+ def load_library(lib, name)
+ raise ArgumentError, "Libraries must be passed as strings not #{lib.class}" unless lib.is_a?(String)
- begin
- require lib
- rescue SystemExit,NoMemoryError
- raise
- rescue Exception
- Puppet.debug "Failed to load library '#{lib}' for feature '#{name}'"
- return false
- end
- true
+ begin
+ require lib
+ rescue SystemExit,NoMemoryError
+ raise
+ rescue Exception
+ Puppet.debug "Failed to load library '#{lib}' for feature '#{name}'"
+ return false
end
+ true
+ end
end