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 10 def self.init_dispatch 11 dispatch :hiera_splat do 12 scope_param 13 param 'Tuple[String, Any, Any, 1, 3]', :args 14 end 15 16 dispatch :hiera_no_default do 17 scope_param 18 param 'String',:key 19 end 20 21 dispatch :hiera_with_default do 22 scope_param 23 param 'String',:key 24 param 'Any', :default 25 optional_param 'Any', :override 26 end 27 28 dispatch :hiera_block1 do 29 scope_param 30 param 'String', :key 31 block_param 'Callable[1,1]', :default_block 32 end 33 34 dispatch :hiera_block2 do 35 scope_param 36 param 'String', :key 37 param 'Any', :override 38 block_param 'Callable[1,1]', :default_block 39 end 40 end
Public Instance Methods
hiera_block1(scope, key, &default_block)
click to toggle source
# File lib/hiera/puppet_function.rb 54 def hiera_block1(scope, key, &default_block) 55 post_lookup(scope, key, lookup(scope, key, nil, false, nil, &default_block)) 56 end
hiera_block2(scope, key, override, &default_block)
click to toggle source
# File lib/hiera/puppet_function.rb 58 def hiera_block2(scope, key, override, &default_block) 59 post_lookup(scope, key, lookup(scope, key, nil, false, override, &default_block)) 60 end
hiera_no_default(scope, key)
click to toggle source
# File lib/hiera/puppet_function.rb 46 def hiera_no_default(scope, key) 47 post_lookup(scope, key, lookup(scope, key, nil, false, nil)) 48 end
hiera_splat(scope, args)
click to toggle source
# File lib/hiera/puppet_function.rb 42 def hiera_splat(scope, args) 43 hiera(scope, *args) 44 end
hiera_with_default(scope, key, default, override = nil)
click to toggle source
# File lib/hiera/puppet_function.rb 50 def hiera_with_default(scope, key, default, override = nil) 51 post_lookup(scope, key, lookup(scope, key, default, true, override)) 52 end
lookup(scope, key, default, has_default, override, &default_block)
click to toggle source
# File lib/hiera/puppet_function.rb 62 def lookup(scope, key, default, has_default, override, &default_block) 63 unless Puppet[:strict] == :off 64 #TRANSLATORS 'lookup' is a puppet function and should not be translated 65 message = _("The function '%{class_name}' is deprecated in favor of using 'lookup'.") % { class_name: self.class.name } 66 message += ' '+ _("See https://puppet.com/docs/puppet/%{minor_version}/deprecated_language.html") % 67 { minor_version: Puppet.minor_version } 68 Puppet.warn_once('deprecations', self.class.name, message) 69 end 70 lookup_invocation = Puppet::Pops::Lookup::Invocation.new(scope, {}, {}) 71 adapter = lookup_invocation.lookup_adapter 72 lookup_invocation.set_hiera_xxx_call 73 lookup_invocation.set_global_only unless adapter.global_only? || adapter.has_environment_data_provider?(lookup_invocation) 74 lookup_invocation.set_hiera_v3_location_overrides(override) unless override.nil? || override.is_a?(Array) && override.empty? 75 Puppet::Pops::Lookup.lookup(key, nil, default, has_default, merge_type, lookup_invocation, &default_block) 76 end
merge_type()
click to toggle source
# File lib/hiera/puppet_function.rb 78 def merge_type 79 :first 80 end
post_lookup(scope, key, result)
click to toggle source
# File lib/hiera/puppet_function.rb 82 def post_lookup(scope, key, result) 83 result 84 end