Class: Hiera::Scope

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

Constant Summary collapse

CALLING_CLASS =
"calling_class"
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.



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

def initialize(real)
  @real = real
end

Instance Attribute Details

#realObject (readonly)

Returns the value of attribute real.



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

def real
  @real
end

Instance Method Details

#[](key) ⇒ Object



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

def [](key)
  if key == CALLING_CLASS
    ans = find_hostclass(@real)
  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



37
38
39
# File 'lib/hiera/scope.rb', line 37

def catalog
  @real.catalog
end

#compilerObject



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

def compiler
  @real.compiler
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'lib/hiera/scope.rb', line 29

def include?(key)
  if key == CALLING_CLASS or key == CALLING_MODULE
    true
  else
    @real.lookupvar(key) != ""
  end
end

#resourceObject



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

def resource
  @real.resource
end