Class: Hiera::Scope

Inherits:
Object show all
Extended by:
Forwardable
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


16
17
18
# File 'lib/hiera/scope.rb', line 16

def initialize(real)
  @real = real
end

Instance Attribute Details

#realObject (readonly)

Returns the value of attribute real


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

def real
  @real
end

Instance Method Details

#[](key) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hiera/scope.rb', line 20

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


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

def catalog
  @real.catalog
end

#compilerObject


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

def compiler
  @real.compiler
end

#exist?(key) ⇒ Boolean


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

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

#include?(key) ⇒ Boolean


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

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

#resourceObject


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

def resource
  @real.resource
end