Module: Puppet::Pops::Lookup::DataProvider Private

Included in:
ConfiguredDataProvider, FunctionProvider
Defined in:
lib/puppet/pops/lookup/data_provider.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

API:

  • private

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.key_typeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



6
7
8
# File 'lib/puppet/pops/lookup/data_provider.rb', line 6

def self.key_type
  @key_type
end

.register_types(loader) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



14
15
16
17
18
# File 'lib/puppet/pops/lookup/data_provider.rb', line 14

def self.register_types(loader)
  tp = Types::TypeParser.singleton
  @key_type = tp.parse('RichDataKey', loader)
  @value_type = tp.parse('RichData', loader)
end

.value_typeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



10
11
12
# File 'lib/puppet/pops/lookup/data_provider.rb', line 10

def self.value_type
  @value_type
end

Instance Method Details

#key_lookup(key, lookup_invocation, merge) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Performs a lookup with an endless recursion check.

Parameters:

  • The key to lookup

  • The current lookup invocation

  • Merge strategy or hash with strategy and options

API:

  • private



26
27
28
# File 'lib/puppet/pops/lookup/data_provider.rb', line 26

def key_lookup(key, lookup_invocation, merge)
  lookup_invocation.check(key.to_s) { unchecked_key_lookup(key, lookup_invocation, merge) }
end

#key_lookup_in_default(key, lookup_invocation, merge) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.

Parameters:

  • The key to lookup

  • The current lookup invocation

  • Merge strategy or hash with strategy and options

API:

  • private



37
38
39
# File 'lib/puppet/pops/lookup/data_provider.rb', line 37

def key_lookup_in_default(key, lookup_invocation, merge)
  throw :no_such_key
end

#lookup(key, lookup_invocation, merge) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



41
42
43
# File 'lib/puppet/pops/lookup/data_provider.rb', line 41

def lookup(key, lookup_invocation, merge)
  lookup_invocation.check(key.to_s) { unchecked_key_lookup(key, lookup_invocation, merge) }
end

#module_nameString?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the name of the module that this provider belongs to nor nil if it doesn’t belong to a module.

Returns:

  • the name of the module that this provider belongs to nor nil if it doesn’t belong to a module

API:

  • private



57
58
59
# File 'lib/puppet/pops/lookup/data_provider.rb', line 57

def module_name
  nil
end

#nameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the name of the this data provider.

Returns:

  • the name of the this data provider

Raises:

API:

  • private



62
63
64
# File 'lib/puppet/pops/lookup/data_provider.rb', line 62

def name
  raise NotImplementedError, "Subclass of #{DataProvider.name} must implement 'name' method"
end

#unchecked_key_lookup(key, lookup_invocation, merge) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

  • The key to lookup

  • The current lookup invocation

  • Merge strategy, merge strategy name, strategy and options hash, or nil (implies “first found”)

Returns:

  • the found object

Raises:

API:

  • private



52
53
54
# File 'lib/puppet/pops/lookup/data_provider.rb', line 52

def unchecked_key_lookup(key, lookup_invocation, merge)
  raise NotImplementedError, "Subclass of #{DataProvider.name} must implement 'unchecked_lookup' method"
end

#validate_data_hash(data_hash, &block) ⇒ Hash{String=>Object}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

  • The data hash

Returns:

  • The data hash

API:

  • private



75
76
77
# File 'lib/puppet/pops/lookup/data_provider.rb', line 75

def validate_data_hash(data_hash, &block)
  Types::TypeAsserter.assert_instance_of(nil, Types::PHashType::DEFAULT, data_hash, &block)
end

#validate_data_value(value, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

  • The data provider that produced the hash

Returns:

  • The data value

API:

  • private



83
84
85
86
87
88
89
90
# File 'lib/puppet/pops/lookup/data_provider.rb', line 83

def validate_data_value(value, &block)
  # The DataProvider.value_type is self recursive so further recursive check of collections is needed here
  unless value_is_validated? || DataProvider.value_type.instance?(value)
    actual_type = Types::TypeCalculator.singleton.infer(value)
    raise Types::TypeAssertionError.new("#{yield} has wrong type, expects Puppet::LookupValue, got #{actual_type}", DataProvider.value_type, actual_type)
  end
  value
end

#value_is_validated?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

API:

  • private



67
68
69
# File 'lib/puppet/pops/lookup/data_provider.rb', line 67

def value_is_validated?
  false
end