Class: Hiera::PuppetFunction

Overview

Provides the base class for the puppet functions hiera, hiera_array, hiera_hash, and hiera_include. The actual function definitions will call init_dispatch and override the merge_type and post_lookup methods.

See Also:

  • hiera_include.rb under lib/puppet/functions for sample usage

Instance Attribute Summary

Attributes inherited from Puppet::Pops::Functions::Function

#loader

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Puppet::Functions::InternalFunction

builder, #call_function_with_scope

Methods inherited from Puppet::Functions::Function

argument_mismatch, builder, dispatch, local_types, new

Methods inherited from Puppet::Pops::Functions::Function

#call, #call_function, #closure_scope, dispatcher, #initialize, signatures

Constructor Details

This class inherits a constructor from Puppet::Pops::Functions::Function

Class Method Details

.init_dispatchObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/hiera/puppet_function.rb', line 11

def self.init_dispatch
  dispatch :hiera_splat do
    scope_param
    param 'Tuple[String, Any, Any, 1, 3]', :args
  end

  dispatch :hiera_no_default do
    scope_param
    param 'String', :key
  end

  dispatch :hiera_with_default do
    scope_param
    param 'String', :key
    param 'Any',   :default
    optional_param 'Any', :override
  end

  dispatch :hiera_block1 do
    scope_param
    param 'String',              :key
    block_param 'Callable[1,1]', :default_block
  end

  dispatch :hiera_block2 do
    scope_param
    param 'String',              :key
    param 'Any',                 :override
    block_param 'Callable[1,1]', :default_block
  end
end

Instance Method Details

#hiera_block1(scope, key, &default_block) ⇒ Object



55
56
57
# File 'lib/hiera/puppet_function.rb', line 55

def hiera_block1(scope, key, &default_block)
  post_lookup(scope, key, lookup(scope, key, nil, false, nil, &default_block))
end

#hiera_block2(scope, key, override, &default_block) ⇒ Object



59
60
61
# File 'lib/hiera/puppet_function.rb', line 59

def hiera_block2(scope, key, override, &default_block)
  post_lookup(scope, key, lookup(scope, key, nil, false, override, &default_block))
end

#hiera_no_default(scope, key) ⇒ Object



47
48
49
# File 'lib/hiera/puppet_function.rb', line 47

def hiera_no_default(scope, key)
  post_lookup(scope, key, lookup(scope, key, nil, false, nil))
end

#hiera_splat(scope, args) ⇒ Object



43
44
45
# File 'lib/hiera/puppet_function.rb', line 43

def hiera_splat(scope, args)
  hiera(scope, *args)
end

#hiera_with_default(scope, key, default, override = nil) ⇒ Object



51
52
53
# File 'lib/hiera/puppet_function.rb', line 51

def hiera_with_default(scope, key, default, override = nil)
  post_lookup(scope, key, lookup(scope, key, default, true, override))
end

#lookup(scope, key, default, has_default, override, &default_block) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/hiera/puppet_function.rb', line 63

def lookup(scope, key, default, has_default, override, &default_block)
  unless Puppet[:strict] == :off
    # TRANSLATORS 'lookup' is a puppet function and should not be translated
    message = _("The function '%{class_name}' is deprecated in favor of using 'lookup'.") % { class_name: self.class.name }
    message += ' ' + _("See https://puppet.com/docs/puppet/%{minor_version}/deprecated_language.html") %
                     { minor_version: Puppet.minor_version }
    Puppet.warn_once('deprecations', self.class.name, message)
  end
  lookup_invocation = Puppet::Pops::Lookup::Invocation.new(scope, {}, {})
  adapter = lookup_invocation.lookup_adapter
  lookup_invocation.set_hiera_xxx_call
  lookup_invocation.set_global_only unless adapter.global_only? || adapter.has_environment_data_provider?(lookup_invocation)
  lookup_invocation.set_hiera_v3_location_overrides(override) unless override.nil? || override.is_a?(Array) && override.empty?
  Puppet::Pops::Lookup.lookup(key, nil, default, has_default, merge_type, lookup_invocation, &default_block)
end

#merge_typeObject



79
80
81
# File 'lib/hiera/puppet_function.rb', line 79

def merge_type
  :first
end

#post_lookup(scope, key, result) ⇒ Object



83
84
85
# File 'lib/hiera/puppet_function.rb', line 83

def post_lookup(scope, key, result)
  result
end