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

attr_injected, attr_injected_producer, builder, #call_function_with_scope

Methods inherited from Puppet::Functions::Function

builder, dispatch

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



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

def hiera_block1(scope, key, &default_block)
  common(scope, key, 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)
  common(scope, key, 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, 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
52
53
# File 'lib/hiera/puppet_function.rb', line 49

def hiera_with_default(scope, key, default, override = nil)
  undefined = (@@undefined_value ||= Object.new)
  result = lookup(scope, key, undefined, override)
  post_lookup(scope, key, result.equal?(undefined) ? default : result)
end

#lookup(scope, key, default, override) ⇒ Object



71
72
73
# File 'lib/hiera/puppet_function.rb', line 71

def lookup(scope, key, default, override)
  HieraPuppet.lookup(key, default, scope, override, merge_type)
end

#merge_typeObject



75
76
77
# File 'lib/hiera/puppet_function.rb', line 75

def merge_type
  :priority
end

#post_lookup(scope, key, result) ⇒ Object



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

def post_lookup(scope, key, result)
  result
end