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

#closure_scope, #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, dispatcher, #initialize, signatures

Constructor Details

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

Class Method Details

.init_dispatchObject


9
10
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
# File 'lib/hiera/puppet_function.rb', line 9

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


53
54
55
# File 'lib/hiera/puppet_function.rb', line 53

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


57
58
59
# File 'lib/hiera/puppet_function.rb', line 57

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


45
46
47
# File 'lib/hiera/puppet_function.rb', line 45

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

#hiera_splat(scope, args) ⇒ Object


41
42
43
# File 'lib/hiera/puppet_function.rb', line 41

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

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


49
50
51
# File 'lib/hiera/puppet_function.rb', line 49

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


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

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


77
78
79
# File 'lib/hiera/puppet_function.rb', line 77

def merge_type
  :first
end

#post_lookup(scope, key, result) ⇒ Object


81
82
83
# File 'lib/hiera/puppet_function.rb', line 81

def post_lookup(scope, key, result)
  result
end