class Hiera::PuppetFunction

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 hiera_array.rb, hiera_include.rb under lib/puppet/functions for sample usage

Public Class Methods

init_dispatch() click to toggle source
   # File lib/hiera/puppet_function.rb
 9 def self.init_dispatch
10   dispatch :hiera_splat do
11     scope_param
12     param 'Tuple[String, Any, Any, 1, 3]', :args
13   end
14 
15   dispatch :hiera_no_default do
16     scope_param
17     param 'String',:key
18   end
19 
20   dispatch :hiera_with_default do
21     scope_param
22     param 'String',:key
23     param 'Any',   :default
24     optional_param 'Any',   :override
25   end
26 
27   dispatch :hiera_block1 do
28     scope_param
29     param 'String',              :key
30     block_param 'Callable[1,1]', :default_block
31   end
32 
33   dispatch :hiera_block2 do
34     scope_param
35     param 'String',              :key
36     param 'Any',                 :override
37     block_param 'Callable[1,1]', :default_block
38   end
39 end

Public Instance Methods

hiera_block1(scope, key, &default_block) click to toggle source
   # File lib/hiera/puppet_function.rb
53 def hiera_block1(scope, key, &default_block)
54   post_lookup(scope, key, lookup(scope, key, nil, false, nil, &default_block))
55 end
hiera_block2(scope, key, override, &default_block) click to toggle source
   # File lib/hiera/puppet_function.rb
57 def hiera_block2(scope, key, override, &default_block)
58   post_lookup(scope, key, lookup(scope, key, nil, false, override, &default_block))
59 end
hiera_no_default(scope, key) click to toggle source
   # File lib/hiera/puppet_function.rb
45 def hiera_no_default(scope, key)
46   post_lookup(scope, key, lookup(scope, key, nil, false, nil))
47 end
hiera_splat(scope, args) click to toggle source
   # File lib/hiera/puppet_function.rb
41 def hiera_splat(scope, args)
42   hiera(scope, *args)
43 end
hiera_with_default(scope, key, default, override = nil) click to toggle source
   # File lib/hiera/puppet_function.rb
49 def hiera_with_default(scope, key, default, override = nil)
50   post_lookup(scope, key, lookup(scope, key, default, true, override))
51 end
lookup(scope, key, default, has_default, override, &default_block) click to toggle source
   # File lib/hiera/puppet_function.rb
61 def lookup(scope, key, default, has_default, override, &default_block)
62   unless Puppet[:strict] == :off
63     #TRANSLATORS 'lookup' is a puppet function and should not be translated
64     message = _("The function '%{class_name}' is deprecated in favor of using 'lookup'.") % { class_name: self.class.name }
65     message += ' '+ _("See https://puppet.com/docs/puppet/%{minor_version}/deprecated_language.html") %
66         { minor_version: Puppet.minor_version }
67     Puppet.warn_once('deprecations', self.class.name, message)
68   end
69   lookup_invocation = Puppet::Pops::Lookup::Invocation.new(scope, {}, {})
70   adapter = lookup_invocation.lookup_adapter
71   lookup_invocation.set_hiera_xxx_call
72   lookup_invocation.set_global_only unless adapter.global_only? || adapter.has_environment_data_provider?(lookup_invocation)
73   lookup_invocation.set_hiera_v3_location_overrides(override) unless override.nil? || override.is_a?(Array) && override.empty?
74   Puppet::Pops::Lookup.lookup(key, nil, default, has_default, merge_type, lookup_invocation, &default_block)
75 end
merge_type() click to toggle source
   # File lib/hiera/puppet_function.rb
77 def merge_type
78   :first
79 end
post_lookup(scope, key, result) click to toggle source
   # File lib/hiera/puppet_function.rb
81 def post_lookup(scope, key, result)
82   result
83 end