Class: Facter::Core::Aggregate
- Inherits:
-
Object
- Object
- Facter::Core::Aggregate
- Includes:
- Resolvable, Suitable
- Defined in:
- lib/facter/core/aggregate.rb
Overview
Aggregates provide a mechanism for facts to be resolved in multiple steps.
Aggregates are evaluated in two parts: generating individual chunks and then aggregating all chunks together. Each chunk is a block of code that generates a value, and may depend on other chunks when it runs. After all chunks have been evaluated they are passed to the aggregate block as Hash<name, result>. The aggregate block converts the individual chunks into a single value that is returned as the final value of the aggregate.
Defined Under Namespace
Classes: DependencyError
Instance Attribute Summary collapse
- #confines ⇒ Object readonly
- #deps ⇒ Object readonly
- #fact ⇒ Facter::Util::Fact readonly private
- #name ⇒ Object readonly
Attributes included from Resolvable
Attributes included from Suitable
Instance Method Summary collapse
-
#aggregate {|Hash<Symbol, Object>| ... } ⇒ void
Define how all chunks should be combined.
-
#chunk(name, opts = {}) {|*Object| ... } ⇒ void
Define a new chunk for the given aggregate.
- #evaluate(&block) ⇒ Object
-
#initialize(name, fact) ⇒ Aggregate
constructor
A new instance of Aggregate.
- #resolution_type ⇒ Object
- #set_options(options) ⇒ Object
Methods included from Resolvable
#flush, #limit, #on_flush, #value
Methods included from Suitable
#confine, #has_weight, #suitable?
Constructor Details
Instance Attribute Details
#confines ⇒ Object (readonly)
36 37 38 |
# File 'lib/facter/core/aggregate.rb', line 36 def confines @confines end |
#deps ⇒ Object (readonly)
30 31 32 |
# File 'lib/facter/core/aggregate.rb', line 30 def deps @deps 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.
41 42 43 |
# File 'lib/facter/core/aggregate.rb', line 41 def fact @fact end |
#name ⇒ Object (readonly)
25 26 27 |
# File 'lib/facter/core/aggregate.rb', line 25 def name @name end |
Instance Method Details
#aggregate {|Hash<Symbol, Object>| ... } ⇒ void
This method returns an undefined value.
Define how all chunks should be combined
139 140 141 142 143 144 145 |
# File 'lib/facter/core/aggregate.rb', line 139 def aggregate(&block) if block_given? @aggregate = block else raise ArgumentError, "#{self.class.name}#aggregate requires a block" end end |
#chunk(name, opts = {}) {|*Object| ... } ⇒ void
This method returns an undefined value.
Define a new chunk for the given aggregate
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/facter/core/aggregate.rb', line 98 def chunk(name, opts = {}, &block) if not block_given? raise ArgumentError, "#{self.class.name}#chunk requires a block" end deps = Array(opts.delete(:require)) if not opts.empty? raise ArgumentError, "Unexpected options passed to #{self.class.name}#chunk: #{opts.keys.inspect}" end @deps[name] = deps @chunks[name] = block end |
#evaluate(&block) ⇒ Object
72 73 74 |
# File 'lib/facter/core/aggregate.rb', line 72 def evaluate(&block) instance_eval(&block) end |
#resolution_type ⇒ Object
147 148 149 |
# File 'lib/facter/core/aggregate.rb', line 147 def resolution_type :aggregate end |
#set_options(options) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/facter/core/aggregate.rb', line 54 def () if [:name] @name = .delete(:name) end if .has_key?(:timeout) @timeout = .delete(:timeout) end if .has_key?(:weight) @weight = .delete(:weight) end if not .keys.empty? raise ArgumentError, "Invalid aggregate options #{.keys.inspect}" end end |