Class: Puppet::Pops::FirstFoundStrategy

Inherits:
MergeStrategy show all
Defined in:
lib/puppet/pops/merge_strategy.rb

Overview

Simple strategy that returns the first value found. It never merges any values.

Direct Known Subclasses

DefaultMergeStrategy

Constant Summary collapse

INSTANCE =
new(EMPTY_HASH)

Constants inherited from MergeStrategy

MergeStrategy::NOT_FOUND

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MergeStrategy

add_strategy, #configuration, #convert_value, #initialize, merge, #merge, #merge_lookup, #merge_single, #options, options_t, strategy, strategy_keys

Constructor Details

This class inherits a constructor from Puppet::Pops::MergeStrategy

Class Method Details

.keyObject



213
214
215
# File 'lib/puppet/pops/merge_strategy.rb', line 213

def self.key
  :first
end

Instance Method Details

#lookup(lookup_variants, _) ⇒ Object

Returns the first value found

Parameters:

  • lookup_variants (Array)

    The variants to pass as second argument to the given block

Returns:

  • (Object)

    the merged value



223
224
225
226
227
228
# File 'lib/puppet/pops/merge_strategy.rb', line 223

def lookup(lookup_variants, _)
  # First found does not continue when a root key was found and a subkey wasn't since that would
  # simulate a hash merge
  lookup_variants.each { |lookup_variant| catch(:no_such_key) { return yield(lookup_variant) } }
  throw :no_such_key
end