Module: Facter::Core::Suitable
- Included in:
- Aggregate, Util::Resolution
- Defined in:
- lib/facter/core/suitable.rb
Overview
The Suitable mixin provides mechanisms for confining objects to run on certain platforms and determining the run precedence of these objects.
Classes that include the Suitable mixin should define a ‘#confines` method that returns an Array of zero or more Facter::Util::Confine objects.
Instance Attribute Summary collapse
-
#weight ⇒ Integer
private
Returns the importance of this resolution.
Instance Method Summary collapse
-
#confine(confines = nil, &block) ⇒ void
Sets the conditions for this resolution to be used.
-
#has_weight(weight) ⇒ void
Sets the weight of this resolution.
-
#suitable? ⇒ Boolean
private
Is this resolution mechanism suitable on the system in question?.
Instance Attribute Details
#weight ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the importance of this resolution. If the weight was not given, the number of confines is used instead (so that a more specific resolution wins over a less specific one).
99 100 101 102 103 104 105 |
# File 'lib/facter/core/suitable.rb', line 99 def weight if @weight @weight else @confines.length end end |
Instance Method Details
#confine(confines) ⇒ void #confine(confines, &block) {|value| ... } ⇒ void #confine(&block) ⇒ void
This method returns an undefined value.
Sets the conditions for this resolution to be used. This method accepts multiple forms of arguments to determine suitability.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/facter/core/suitable.rb', line 74 def confine(confines = nil, &block) case confines when Hash confines.each do |fact, values| @confines.push Facter::Util::Confine.new(fact, *values) end else if block if confines @confines.push Facter::Util::Confine.new(confines, &block) else @confines.push Facter::Util::Confine.new(&block) end else end end end |
#has_weight(weight) ⇒ void
This method returns an undefined value.
Sets the weight of this resolution. If multiple suitable resolutions are found, the one with the highest weight will be used. If weight is not given, the number of confines set on a resolution will be used as its weight (so that the most specific resolution is used).
22 23 24 |
# File 'lib/facter/core/suitable.rb', line 22 def has_weight(weight) @weight = weight end |
#suitable? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Is this resolution mechanism suitable on the system in question?
110 111 112 |
# File 'lib/facter/core/suitable.rb', line 110 def suitable? @confines.all? { |confine| confine.true? } end |