Class: Facter::Util::Resolution
- Inherits:
-
Object
- Object
- Facter::Util::Resolution
- Extended by:
- Core::Execution
- Defined in:
- lib/facter/custom_facts/util/resolution.rb
Overview
Instance Attribute Summary collapse
- #code ⇒ Object private
-
#fact ⇒ Facter::Util::Fact
readonly
private
Associated fact with this resolution.
- #fact_type ⇒ Object private
-
#file ⇒ Facter::Util::Fact
readonly
private
Associated fact with this resolution.
-
#last_evaluated ⇒ Facter::Util::Fact
readonly
private
Associated fact with this resolution.
-
#name ⇒ String
The name of this resolution.
- #value ⇒ Object writeonly private
Attributes included from LegacyFacter::Core::Resolvable
Instance Method Summary collapse
-
#<=>(other) ⇒ bool
private
Comparison is done based on weight and fact type.
-
#evaluate(&block) ⇒ String
private
Evaluate the given block in the context of this resolution.
-
#initialize(name, fact) ⇒ Facter::Util::Resolution
constructor
Create a new resolution mechanism.
-
#options(options) ⇒ nil
private
Sets options for the aggregate fact.
-
#resolution_type ⇒ Symbol
private
Returns the fact’s resolution type.
-
#setcode(string = nil, &block) ⇒ Facter::Util::Resolution
Sets the code block or external program that will be evaluated to get the value of the fact.
Methods included from Core::Execution
absolute_path?, exec, execute, execute_command, expand_command, impl, search_paths, which, with_env
Methods included from LegacyFacter::Core::Suitable
#confine, #has_weight, #suitable?, #weight
Methods included from LegacyFacter::Core::Resolvable
#flush, #limit, #on_flush, #value
Constructor Details
#initialize(name, fact) ⇒ Facter::Util::Resolution
Create a new resolution mechanism.
67 68 69 70 71 72 73 74 |
# File 'lib/facter/custom_facts/util/resolution.rb', line 67 def initialize(name, fact) @name = name @fact = fact @confines = [] @value = nil @timeout = 0 @weight = nil end |
Instance Attribute Details
#code ⇒ Object
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.
18 19 20 |
# File 'lib/facter/custom_facts/util/resolution.rb', line 18 def code @code end |
#fact ⇒ Facter::Util::Fact (readonly)
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 Associated fact with this resolution.
56 57 58 |
# File 'lib/facter/custom_facts/util/resolution.rb', line 56 def fact @fact end |
#fact_type ⇒ Object
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.
18 19 20 |
# File 'lib/facter/custom_facts/util/resolution.rb', line 18 def fact_type @fact_type end |
#file ⇒ Facter::Util::Fact (readonly)
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 Associated fact with this resolution.
56 57 58 |
# File 'lib/facter/custom_facts/util/resolution.rb', line 56 def file @file end |
#last_evaluated ⇒ Facter::Util::Fact (readonly)
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 Associated fact with this resolution.
56 57 58 |
# File 'lib/facter/custom_facts/util/resolution.rb', line 56 def last_evaluated @last_evaluated end |
#name ⇒ String
The name of this resolution. The resolution name should be unique with
respect to the given fact.
49 50 51 |
# File 'lib/facter/custom_facts/util/resolution.rb', line 49 def name @name end |
#value=(value) ⇒ Object (writeonly)
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.
21 22 23 |
# File 'lib/facter/custom_facts/util/resolution.rb', line 21 def value=(value) @value = value end |
Instance Method Details
#<=>(other) ⇒ bool
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.
Comparison is done based on weight and fact type.
The greater the weight, the higher the priority.
If weights are equal, we consider external facts greater than custom facts.
161 162 163 164 165 166 167 |
# File 'lib/facter/custom_facts/util/resolution.rb', line 161 def <=>(other) if weight == other.weight compare_equal_weights(other) else weight <=> other.weight end end |
#evaluate(&block) ⇒ String
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.
Evaluate the given block in the context of this resolution. If a block has already been evaluated emit a warning to that effect.
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/facter/custom_facts/util/resolution.rb', line 91 def evaluate(&block) if @last_evaluated msg = +"Already evaluated #{@name}" msg << " at #{@last_evaluated}" if msg.is_a? String msg << ', reevaluating anyways' log.warn msg end instance_eval(&block) @last_evaluated = block.source_location.join(':') end |
#options(options) ⇒ nil
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.
Sets options for the aggregate fact
109 110 111 112 113 114 115 116 117 |
# File 'lib/facter/custom_facts/util/resolution.rb', line 109 def () = %i[name value timeout weight fact_type file is_env] .each do |option_name| instance_variable_set("@#{option_name}", .delete(option_name)) if .key?(option_name) end raise ArgumentError, "Invalid resolution options #{.keys.inspect}" unless .keys.empty? end |
#resolution_type ⇒ Symbol
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 fact’s resolution type
81 82 83 |
# File 'lib/facter/custom_facts/util/resolution.rb', line 81 def resolution_type :simple end |
#setcode(string) ⇒ Facter::Util::Resolution #setcode(&block) ⇒ Facter::Util::Resolution
Sets the code block or external program that will be evaluated to get the value of the fact.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/facter/custom_facts/util/resolution.rb', line 136 def setcode(string = nil, &block) if string @code = proc do output = Facter::Core::Execution.execute(string, on_fail: nil) if output.nil? || output.empty? nil else output end end elsif block_given? @code = block else raise ArgumentError, 'You must pass either code or a block' end self end |