Module: PuppetDebugger::Support::Scope

Included in:
PuppetDebugger::Support
Defined in:
lib/puppet-debugger/support/scope.rb

Instance Method Summary collapse

Instance Method Details

#create_scopePuppet::Pops::Scope

Returns - returns a puppet scope object.

Returns:

  • (Puppet::Pops::Scope)
    • returns a puppet scope object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/puppet-debugger/support/scope.rb', line 17

def create_scope
  do_initialize
  begin
    # creates a new compiler for each scope
    scope = Puppet::Parser::Scope.new(compiler)
    # creates a node class
    scope.source = Puppet::Resource::Type.new(:node, node.name)
    scope.parent = compiler.topscope
    # compiling will load all the facts into the scope
    # without this step facts will not get resolved
    scope.compiler.compile # this will load everything into the scope
  rescue StandardError => e
    err = parse_error(e)
    raise err
  end
  scope
end

#scopePuppet::Pops::Scope

Returns - returns a puppet scope object.

Returns:

  • (Puppet::Pops::Scope)
    • returns a puppet scope object



12
13
14
# File 'lib/puppet-debugger/support/scope.rb', line 12

def scope
  @scope ||= create_scope
end

#scope_varsHash

Returns - returns a hash of variables that are currently in scope.

Returns:

  • (Hash)
    • returns a hash of variables that are currently in scope



36
37
38
39
# File 'lib/puppet-debugger/support/scope.rb', line 36

def scope_vars
  vars = scope.to_hash.delete_if { |key, _value| node.facts.values.key?(key.to_sym) }
  vars['facts'] = 'removed by the puppet-debugger'
end

#set_scope(value) ⇒ Object

Parameters:

  • - (Puppet::Pops::Scope)

    Scope object or nil



7
8
9
# File 'lib/puppet-debugger/support/scope.rb', line 7

def set_scope(value)
  @scope = value
end