class Hiera::Scope
Constants
- CALLING_CLASS
- CALLING_CLASS_PATH
- CALLING_KEYS
- CALLING_MODULE
- EMPTY_STRING
- MODULE_NAME
Attributes
real[R]
Public Class Methods
new(real)
click to toggle source
# File lib/hiera/scope.rb 17 def initialize(real) 18 @real = real 19 end
Public Instance Methods
[](key)
click to toggle source
# File lib/hiera/scope.rb 21 def [](key) 22 if key == CALLING_CLASS 23 ans = find_hostclass(@real) 24 elsif key == CALLING_CLASS_PATH 25 ans = find_hostclass(@real).gsub(/::/, '/') 26 elsif key == CALLING_MODULE 27 ans = safe_lookupvar(MODULE_NAME) 28 else 29 ans = safe_lookupvar(key) 30 end 31 ans == EMPTY_STRING ? nil : ans 32 end
catalog()
click to toggle source
# File lib/hiera/scope.rb 64 def catalog 65 @real.catalog 66 end
compiler()
click to toggle source
# File lib/hiera/scope.rb 72 def compiler 73 @real.compiler 74 end
exist?(key)
click to toggle source
# File lib/hiera/scope.rb 56 def exist?(key) 57 CALLING_KEYS.include?(key) || @real.exist?(key) 58 end
include?(key)
click to toggle source
# File lib/hiera/scope.rb 60 def include?(key) 61 CALLING_KEYS.include?(key) || @real.include?(key) 62 end
resource()
click to toggle source
# File lib/hiera/scope.rb 68 def resource 69 @real.resource 70 end
Private Instance Methods
find_hostclass(scope)
click to toggle source
# File lib/hiera/scope.rb 76 def find_hostclass(scope) 77 if scope.source and scope.source.type == :hostclass 78 return scope.source.name.downcase 79 elsif scope.parent 80 return find_hostclass(scope.parent) 81 else 82 return nil 83 end 84 end
safe_lookupvar(key)
click to toggle source
This method is used to handle the throw of :undefined_variable since when strict variables is not in effect, missing handling of the throw leads to a more expensive code path.
# File lib/hiera/scope.rb 38 def safe_lookupvar(key) 39 reason = catch :undefined_variable do 40 return @real.lookupvar(key) 41 end 42 43 case Puppet[:strict] 44 when :off 45 # do nothing 46 when :warning 47 Puppet.warn_once(Puppet::Parser::Scope::UNDEFINED_VARIABLES_KIND, _("Variable: %{name}") % { name: key }, 48 _("Undefined variable '%{name}'; %{reason}") % { name: key, reason: reason } ) 49 when :error 50 raise ArgumentError, _("Undefined variable '%{name}'; %{reason}") % { name: key, reason: reason } 51 end 52 nil 53 end