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, options_t, strategy, strategy_keys

Constructor Details

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

Class Method Details

.keyObject


208
209
210
# File 'lib/puppet/pops/merge_strategy.rb', line 208

def self.key
  :first
end

Instance Method Details

#lookup(lookup_variants, _) ⇒ Object

Returns the first value found


218
219
220
221
222
223
# File 'lib/puppet/pops/merge_strategy.rb', line 218

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