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

Included in:
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

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



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

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.



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

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.



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

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:

  • 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



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

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:

  • 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



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

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.



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

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:

  • (String, nil)

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



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

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:

  • (String)

    the name of the this data provider

Raises:

  • (NotImplementedError)


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

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)


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

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:

  • data_hash (Hash{String=>Object})

    The data hash

Returns:



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

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:

  • data_provider (DataProvider)

    The data provider that produced the hash

Returns:



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

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:

  • (Boolean)


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

def value_is_validated?
  false
end