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.



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

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.



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

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.



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

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



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

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



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

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.



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

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



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

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)


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

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)


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

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:

  • (Hash{String=>Object})

    The data hash



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

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:



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

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)


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

def value_is_validated?
  false
end