module Puppet::Pops::Lookup::DataProvider
@api private
Public Class Methods
# File lib/puppet/pops/lookup/data_provider.rb 5 def self.key_type 6 @key_type 7 end
# File lib/puppet/pops/lookup/data_provider.rb 13 def self.register_types(loader) 14 tp = Types::TypeParser.singleton 15 @key_type = tp.parse('RichDataKey', loader) 16 @value_type = tp.parse('RichData', loader) 17 end
# File lib/puppet/pops/lookup/data_provider.rb 9 def self.value_type 10 @value_type 11 end
Public Instance Methods
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 25 def key_lookup(key, lookup_invocation, merge) 26 lookup_invocation.check(key.to_s) { unchecked_key_lookup(key, lookup_invocation, merge) } 27 end
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 36 def key_lookup_in_default(key, lookup_invocation, merge) 37 throw :no_such_key 38 end
# File lib/puppet/pops/lookup/data_provider.rb 40 def lookup(key, lookup_invocation, merge) 41 lookup_invocation.check(key.to_s) { unchecked_key_lookup(key, lookup_invocation, merge) } 42 end
@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 56 def module_name 57 nil 58 end
@return [String] the name of the this data provider
# File lib/puppet/pops/lookup/data_provider.rb 61 def name 62 raise NotImplementedError, "Subclass of #{DataProvider.name} must implement 'name' method" 63 end
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 51 def unchecked_key_lookup(key, lookup_invocation, merge) 52 raise NotImplementedError, "Subclass of #{DataProvider.name} must implement 'unchecked_lookup' method" 53 end
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 74 def validate_data_hash(data_hash, &block) 75 Types::TypeAsserter.assert_instance_of(nil, Types::PHashType::DEFAULT, data_hash, &block) 76 end
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 82 def validate_data_value(value, &block) 83 # The DataProvider.value_type is self recursive so further recursive check of collections is needed here 84 unless value_is_validated? || DataProvider.value_type.instance?(value) 85 actual_type = Types::TypeCalculator.singleton.infer(value) 86 raise Types::TypeAssertionError.new("#{yield} has wrong type, expects Puppet::LookupValue, got #{actual_type}", DataProvider.value_type, actual_type) 87 end 88 value 89 end
@returns `true` if the value provided by this instance can always be trusted, `false` otherwise
# File lib/puppet/pops/lookup/data_provider.rb 66 def value_is_validated? 67 false 68 end