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

Included in:
Puppet::Plugins::DataProviders::DataProvider, 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

.ensure_types_initializedObject

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/puppet/pops/lookup/data_provider.rb', line 15

def self.ensure_types_initialized
  if @key_type.nil?
    (@key_type, @value_type) = Pcore::register_aliases(
      # The Pcore type for all keys and subkeys in a data hash.
      'Puppet::LookupKey' => 'Variant[String,Numeric]',

      # The Pcore type for all values and sub-values in a data hash. The
      # type is self-recursive to enforce the same constraint on values contained
      # in arrays and hashes
      'Puppet::LookupValue' => "        Variant[\n          Scalar,\n          Undef,\n          Sensitive,\n          Type,\n          Hash[Puppet::LookupKey, Puppet::LookupValue],\n          Array[Puppet::LookupValue]\n        ]\n      PUPPET\n    )\n  end\nend\n"

.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



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

def self.key_type
  ensure_types_initialized
  @key_type
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
13
# File 'lib/puppet/pops/lookup/data_provider.rb', line 10

def self.value_type
  ensure_types_initialized
  @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



44
45
46
# File 'lib/puppet/pops/lookup/data_provider.rb', line 44

def key_lookup(key, lookup_invocation, merge)
  lookup_invocation.check(key.to_s) { unchecked_key_lookup(key, lookup_invocation, merge) }
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



48
49
50
# File 'lib/puppet/pops/lookup/data_provider.rb', line 48

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



64
65
66
# File 'lib/puppet/pops/lookup/data_provider.rb', line 64

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



69
70
71
# File 'lib/puppet/pops/lookup/data_provider.rb', line 69

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



59
60
61
# File 'lib/puppet/pops/lookup/data_provider.rb', line 59

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

#validate_data_entry(data_provider, key, value) ⇒ 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



95
96
97
98
99
# File 'lib/puppet/pops/lookup/data_provider.rb', line 95

def validate_data_entry(data_provider, key, value)
  Types::TypeAsserter.assert_instance_of(nil, DataProvider.key_type, key) { "Key in hash returned from #{data_provider.name}" }
  validate_data_value(data_provider, value, 'in hash ')
  nil
end

#validate_data_hash(data_provider, data_hash) ⇒ 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 valid hash.

Parameters:

  • The data provider that produced the hash

  • The data hash

Returns:

  • The data hash

API:

  • private



78
79
80
81
82
# File 'lib/puppet/pops/lookup/data_provider.rb', line 78

def validate_data_hash(data_provider, data_hash)
  Types::TypeAsserter.assert_instance_of(nil, Types::PHashType::DEFAULT, data_hash) { "Value returned from #{data_provider.name}" }
  data_hash.each_pair { |k, v| validate_data_entry(data_provider, k, v) }
  data_hash
end

#validate_data_value(data_provider, value, where = '') ⇒ 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



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

def validate_data_value(data_provider, value, where = '')
  Types::TypeAsserter.assert_instance_of(nil, DataProvider.value_type, value) { "Value #{where}returned from #{data_provider.name}" }
  case value
  when Hash
    value.each_pair { |k, v| validate_data_entry(data_provider, k, v) }
  when Array
    value.each {|v| validate_data_value(data_provider, v, 'in array ') }
  end
  value
end