lib/custom_facts/core/aggregate.rb
# Define how all chunks should be combined
#
# @api public
#
# @example Merge all chunks
#   aggregate.aggregate do |chunks|
#     final_result = {}
#     chunks.each_value do |chunk|
#       final_result.deep_merge(chunk)
#     end
#     final_result
#   end
#
# @example Sum all chunks
#   aggregate.aggregate do |chunks|
#     total = 0
#     chunks.each_value do |chunk|
#       total += chunk
#     end
#     total
#   end
#
# @yield [Hash<Symbol, Object>] A hash containing chunk names and
#   chunk values
#
# @return [void]
Define how all chunks should be combined
Define how all chunks should be combined
def aggregate(&block)
        raise ArgumentError, "#{self.class.name}#aggregate requires a block" unless block_given?
        @aggregate = block
      end
def aggregate ( & block ) raise ArgumentError , "#{self.class.name}#aggregate requires a block" unless block_given? @aggregate = block end
Define how all chunks should be combined
Define how all chunks should be combined
None
void
block
<not_specific>
]
<not_specific>
A hash containing chunk names and chunk values
A hash containing chunk names and chunk values
api
None
example
Merge all chunks aggregate.aggregate do |chunks| final_result = {} chunks.each_value do |chunk| final_result.deep_merge(chunk) end final_result end
Merge all chunks aggregate . aggregate do |chunks| final_result = {} chunks . each_value do |chunk| final_result . deep_merge ( chunk ) end final_result end
example
Sum all chunks aggregate.aggregate do |chunks| total = 0 chunks.each_value do |chunk| total += chunk end total end
Sum all chunks aggregate . aggregate do |chunks| total = 0 chunks . each_value do |chunk| total + = chunk end total end