Class: Hiera::Scope

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

Constant Summary collapse

CALLING_CLASS =
"calling_class"
CALLING_CLASS_PATH =
"calling_class_path"
CALLING_MODULE =
"calling_module"
MODULE_NAME =
"module_name"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(real) ⇒ Scope

Returns a new instance of Scope.



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

def initialize(real)
  @real = real
end

Instance Attribute Details

#realObject (readonly)

Returns the value of attribute real.



8
9
10
# File 'lib/hiera/scope.rb', line 8

def real
  @real
end

Instance Method Details

#[](key) ⇒ Object



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

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 = @real.lookupvar(MODULE_NAME)
  else
    ans = @real.lookupvar(key)
  end

  if ans.nil? or ans == ""
    nil
  else
    ans
  end
end

#catalogObject



40
41
42
# File 'lib/hiera/scope.rb', line 40

def catalog
  @real.catalog
end

#compilerObject



48
49
50
# File 'lib/hiera/scope.rb', line 48

def compiler
  @real.compiler
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/hiera/scope.rb', line 32

def include?(key)
  if [CALLING_CLASS, CALLING_CLASS_PATH, CALLING_MODULE].include? key
    true
  else
    @real.exist?(key)
  end
end

#resourceObject



44
45
46
# File 'lib/hiera/scope.rb', line 44

def resource
  @real.resource
end