module Puppet::Pops::Lookup::DataProvider

@api private

Public Class Methods

key_type() click to toggle source
  # File lib/puppet/pops/lookup/data_provider.rb
6 def self.key_type
7   @key_type
8 end
register_types(loader) click to toggle source
   # File lib/puppet/pops/lookup/data_provider.rb
14 def self.register_types(loader)
15   tp = Types::TypeParser.singleton
16   @key_type = tp.parse('RichDataKey', loader)
17   @value_type = tp.parse('RichData', loader)
18 end
value_type() click to toggle source
   # File lib/puppet/pops/lookup/data_provider.rb
10 def self.value_type
11   @value_type
12 end

Public Instance Methods

key_lookup(key, lookup_invocation, merge) click to toggle source

Performs a lookup with an endless recursion check.

@param key [LookupKey] The key to lookup @param lookup_invocation [Invocation] The current lookup invocation @param merge [MergeStrategy,String,Hash{String=>Object},nil] Merge strategy or hash with strategy and options

   # File lib/puppet/pops/lookup/data_provider.rb
26 def key_lookup(key, lookup_invocation, merge)
27   lookup_invocation.check(key.to_s) { unchecked_key_lookup(key, lookup_invocation, merge) }
28 end
key_lookup_in_default(key, lookup_invocation, merge) click to toggle source

Performs a lookup using a module default hierarchy with an endless recursion check. All providers except the `ModuleDataProvider` will throw `:no_such_key` if this method is called.

@param key [LookupKey] The key to lookup @param lookup_invocation [Invocation] The current lookup invocation @param merge [MergeStrategy,String,Hash{String=>Object},nil] Merge strategy or hash with strategy and options

   # File lib/puppet/pops/lookup/data_provider.rb
37 def key_lookup_in_default(key, lookup_invocation, merge)
38   throw :no_such_key
39 end
lookup(key, lookup_invocation, merge) click to toggle source
   # File lib/puppet/pops/lookup/data_provider.rb
41 def lookup(key, lookup_invocation, merge)
42   lookup_invocation.check(key.to_s) { unchecked_key_lookup(key, lookup_invocation, merge) }
43 end
module_name() click to toggle source

@return [String,nil] the name of the module that this provider belongs to nor `nil` if it doesn't belong to a module

   # File lib/puppet/pops/lookup/data_provider.rb
57 def module_name
58   nil
59 end
name() click to toggle source

@return [String] the name of the this data provider

   # File lib/puppet/pops/lookup/data_provider.rb
62 def name
63   raise NotImplementedError, "Subclass of #{DataProvider.name} must implement 'name' method"
64 end
unchecked_key_lookup(key, lookup_invocation, merge) click to toggle source

Performs a lookup with the assumption that a recursive check has been made.

@param key [LookupKey] The key to lookup @param lookup_invocation [Invocation] The current lookup invocation @param merge [MergeStrategy,String,Hash{String => Object},nil] Merge strategy, merge strategy name, strategy and options hash, or nil (implies “first found”) @return [Object] the found object @throw :no_such_key when the object is not found

   # File lib/puppet/pops/lookup/data_provider.rb
52 def unchecked_key_lookup(key, lookup_invocation, merge)
53   raise NotImplementedError, "Subclass of #{DataProvider.name} must implement 'unchecked_lookup' method"
54 end
validate_data_hash(data_hash, &block) click to toggle source

Asserts that data_hash is a hash. Will yield to obtain origin of value in case an error is produced

@param data_hash [Hash{String=>Object}] The data hash @return [Hash{String=>Object}] The data hash

   # File lib/puppet/pops/lookup/data_provider.rb
75 def validate_data_hash(data_hash, &block)
76   Types::TypeAsserter.assert_instance_of(nil, Types::PHashType::DEFAULT, data_hash, &block)
77 end
validate_data_value(value, &block) click to toggle source

Asserts that data_value is of valid type. Will yield to obtain origin of value in case an error is produced

@param data_provider [DataProvider] The data provider that produced the hash @return [Object] The data value

   # File lib/puppet/pops/lookup/data_provider.rb
83 def validate_data_value(value, &block)
84   # The DataProvider.value_type is self recursive so further recursive check of collections is needed here
85   unless value_is_validated? || DataProvider.value_type.instance?(value)
86     actual_type = Types::TypeCalculator.singleton.infer(value)
87     raise Types::TypeAssertionError.new("#{yield} has wrong type, expects Puppet::LookupValue, got #{actual_type}", DataProvider.value_type, actual_type)
88   end
89   value
90 end
value_is_validated?() click to toggle source

@returns `true` if the value provided by this instance can always be trusted, `false` otherwise

   # File lib/puppet/pops/lookup/data_provider.rb
67 def value_is_validated?
68   false
69 end