Method: Facter::Core::Aggregate#aggregate

Defined in:
lib/facter/custom_facts/core/aggregate.rb

#aggregate {|Hash<Symbol, Object>| ... } ⇒ Facter::Core::Aggregate

Define how all chunks should be combined

Examples:

Merge all chunks

aggregate.aggregate do |chunks|
  final_result = {}
  chunks.each_value do |chunk|
    final_result.deep_merge(chunk)
  end
  final_result
end

Sum all chunks

aggregate.aggregate do |chunks|
  total = 0
  chunks.each_value do |chunk|
    total += chunk
  end
  total
end

Yields:

  • (Hash<Symbol, Object>)

    A hash containing chunk names and chunk values

Returns:

Raises:

  • (ArgumentError)

Since:

  • 2.0.0



182
183
184
185
186
187
# File 'lib/facter/custom_facts/core/aggregate.rb', line 182

def aggregate(&block)
  raise ArgumentError, "#{self.class.name}#aggregate requires a block" unless block_given?

  @aggregate = block
  self
end