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 =
self.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, strategy, strategy_keys

Constructor Details

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

Class Method Details

.keyObject



203
204
205
# File 'lib/puppet/pops/merge_strategy.rb', line 203

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



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

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