Class: Puppet::Util::Feature
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#add(name, options = {}) ⇒ Object
Create a new feature test.
-
#initialize(path) ⇒ Feature
constructor
Create a new feature collection.
- #load ⇒ Object
- #method_missing(method, *args) ⇒ Object
-
#test(name, options) ⇒ Object
Actually test whether the feature is present.
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/puppet/util/feature.rb', line 55 def method_missing(method, *args) return super unless method.to_s =~ /\?$/ feature = method.to_s.sub(/\?$/, '') @loader.load(feature) respond_to?(method) && self.send(method) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/puppet/util/feature.rb', line 4 def path @path end |
Instance Method Details
#add(name, options = {}) ⇒ Object
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.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/puppet/util/feature.rb', line 13 def add(name, = {}) method = name.to_s + "?" @results.delete(name) if block_given? begin result = yield rescue StandardError,ScriptError => detail warn _("Failed to load feature test for %{name}: %{detail}") % { name: name, detail: detail } result = false end @results[name] = result end (method) do # we return a cached result if: # * if a block is given (and we just evaluated it above) # * if we already have a positive result # * if we've tested this feature before and it failed, but we're # configured to always cache if block_given? || @results[name] || (@results.has_key?(name) && (!Puppet[:always_retry_plugins])) @results[name] else @results[name] = test(name, ) @results[name] end end end |
#load ⇒ Object
51 52 53 |
# File 'lib/puppet/util/feature.rb', line 51 def load @loader.loadall end |
#test(name, options) ⇒ Object
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.
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/puppet/util/feature.rb', line 67 def test(name, ) return true unless ary = [:libs] ary = [ary] unless ary.is_a?(Array) ary.each do |lib| return false unless load_library(lib, name) end # We loaded all of the required libraries true end |