Class Facter::Core::Aggregate
In: lib/facter/core/aggregate.rb
Parent: Object

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.

@api public @since 2.0.0

Methods

Included Modules

Facter::Core::Suitable Facter::Core::Resolvable

Classes and Modules

Class Facter::Core::Aggregate::DependencyError

Attributes

confines  [R]  @!attribute [r] confines
  @return [Array<Facter::Core::Confine>] An array of confines restricting
    this to a specific platform
  @see Facter::Core::Suitable
deps  [R]  @!attribute [r] deps
  @api private
  @return [Facter::Core::DirectedGraph]
fact  [R]  @!attribute [r] fact @return [Facter::Util::Fact] @api private
name  [R]  @!attribute [r] name
  @return [Symbol] The name of the aggregate resolution

Public Class methods

Public Instance methods

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 a new chunk for the given aggregate

@api public

@example Defining a chunk with no dependencies

  aggregate.chunk(:mountpoints) do
    # generate mountpoint information
  end

@example Defining an chunk to add mount options

  aggregate.chunk(:mount_options, :require => [:mountpoints]) do |mountpoints|
    # `mountpoints` is the result of the previous chunk
    # generate mount option information based on the mountpoints
  end

@param name [Symbol] A name unique to this aggregate describing the chunk @param opts [Hash] @options opts [Array<Symbol>, Symbol] :require One or more chunks

  to evaluate and pass to this block.

@yield [*Object] Zero or more chunk results

@return [void]

[Validate]