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

Included in:
Puppet::Plugins::DataProviders::DataProvider, ConfiguredDataProvider, FunctionProvider
Defined in:
lib/puppet/pops/lookup/data_provider.rb

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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ensure_types_initialized ⇒ 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.



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' => <<-PUPPET
        Variant[
          Scalar,
          Undef,
          Sensitive,
          Type,
          Hash[Puppet::LookupKey, Puppet::LookupValue],
          Array[Puppet::LookupValue]
        ]
      PUPPET
    )
  end
end

.key_type ⇒ 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.



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_type ⇒ 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.



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:

  • key (LookupKey) —

    The key to lookup

  • lookup_invocation (Invocation) —

    The current lookup invocation

  • merge (MergeStrategy, String, Hash{String=>Object}, nil) —

    Merge strategy or hash with strategy and options



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.



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_name ⇒ String?

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:

  • (String, nil) —

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



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

def module_name
  nil
end

#name ⇒ String

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:

  • (String) —

    the name of the this data provider

Raises:

  • (NotImplementedError)


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:

  • key (LookupKey) —

    The key to lookup

  • lookup_invocation (Invocation) —

    The current lookup invocation

  • merge (MergeStrategy, String, Hash{String => Object}, nil) —

    Merge strategy, merge strategy name, strategy and options hash, or nil (implies "first found")

Returns:

  • (Object) —

    the found object

Raises:

  • (NotImplementedError)


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.



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:

  • data_provider (DataProvider) —

    The data provider that produced the hash

  • data_hash (Hash{String=>Object}) —

    The data hash

Returns:



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.



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