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.

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.

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.

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.

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_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 hash.

API:

  • private



78
79
80
# 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}" }
end

#validate_data_value(data_provider, 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.

Asserts that data_value is of valid type.

API:

  • private



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

def validate_data_value(data_provider, value)
  # The DataProvider.value_type is self recursive so further recursive check of collections is needed here
  Types::TypeAsserter.assert_instance_of(nil, DataProvider.value_type, value) { "Value returned from #{data_provider.name}" }
end