Class: Hiera::Scope

Inherits:
Object show all
Defined in:
lib/hiera/scope.rb

Constant Summary collapse

CALLING_CLASS =
'calling_class'.freeze
CALLING_CLASS_PATH =
'calling_class_path'.freeze
CALLING_MODULE =
'calling_module'.freeze
MODULE_NAME =
'module_name'.freeze
CALLING_KEYS =
[CALLING_CLASS, CALLING_CLASS_PATH, CALLING_MODULE].freeze
EMPTY_STRING =
''.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(real) ⇒ Scope

Returns a new instance of Scope.



13
14
15
# File 'lib/hiera/scope.rb', line 13

def initialize(real)
  @real = real
end

Instance Attribute Details

#realObject (readonly)

Returns the value of attribute real.



11
12
13
# File 'lib/hiera/scope.rb', line 11

def real
  @real
end

Instance Method Details

#[](key) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hiera/scope.rb', line 17

def [](key)
  if key == CALLING_CLASS
    ans = find_hostclass(@real)
  elsif key == CALLING_CLASS_PATH
    ans = find_hostclass(@real).gsub(/::/, '/')
  elsif key == CALLING_MODULE
    ans = safe_lookupvar(MODULE_NAME)
  else
    ans = safe_lookupvar(key)
  end
  ans == EMPTY_STRING ? nil : ans
end

#catalogObject



60
61
62
# File 'lib/hiera/scope.rb', line 60

def catalog
  @real.catalog
end

#compilerObject



68
69
70
# File 'lib/hiera/scope.rb', line 68

def compiler
  @real.compiler
end

#exist?(key) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/hiera/scope.rb', line 52

def exist?(key)
  CALLING_KEYS.include?(key) || @real.exist?(key)
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/hiera/scope.rb', line 56

def include?(key)
  CALLING_KEYS.include?(key) || @real.include?(key)
end

#resourceObject



64
65
66
# File 'lib/hiera/scope.rb', line 64

def resource
  @real.resource
end