Class: Puppet::Pops::Lookup::Invocation

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/lookup/invocation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, override_values = {}, default_values = {}, explainer = nil) ⇒ Invocation

Creates a context object for a lookup invocation. The object contains the current scope, overrides, and default values and may optionally contain an ExplanationAcceptor instance that will receive book-keeping information about the progress of the lookup.

If the explain argument is a boolean, then false means that no explanation is needed and true means that the default explanation acceptor should be used. The explain argument may also be an instance of the ExplanationAcceptor class.

Parameters:

  • scope (Puppet::Parser::Scope) —

    The scope to use for the lookup

  • override_values (Hash<String,Object>|nil) (defaults to: {}) —

    A map to use as override. Values found here are returned immediately (no merge)

  • default_values (Hash<String,Object>) (defaults to: {}) —

    A map to use as the last resort (but before default)

  • explainer (boolean, Explanainer) (defaults to: nil) —

    An boolean true to use the default explanation acceptor or an explainer instance that will receive information about the lookup



17
18
19
20
21
22
23
24
25
26
# File 'lib/puppet/pops/lookup/invocation.rb', line 17

def initialize(scope, override_values = {}, default_values = {}, explainer = nil)
  @name_stack = []
  @scope = scope
  @override_values = override_values
  @default_values = default_values
  unless explainer.is_a?(Explainer)
    explainer = explainer == true ? Explainer.new : nil
  end
  @explainer = explainer
end

Instance Attribute Details

#default_values ⇒ Object (readonly)



3
4
5
# File 'lib/puppet/pops/lookup/invocation.rb', line 3

def default_values
  @default_values
end

#explainer ⇒ Object (readonly)



3
4
5
# File 'lib/puppet/pops/lookup/invocation.rb', line 3

def explainer
  @explainer
end

#module_name ⇒ Object (readonly)



3
4
5
# File 'lib/puppet/pops/lookup/invocation.rb', line 3

def module_name
  @module_name
end

#override_values ⇒ Object (readonly)



3
4
5
# File 'lib/puppet/pops/lookup/invocation.rb', line 3

def override_values
  @override_values
end

#scope ⇒ Object (readonly)



3
4
5
# File 'lib/puppet/pops/lookup/invocation.rb', line 3

def scope
  @scope
end

Instance Method Details

#check(name) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/puppet/pops/lookup/invocation.rb', line 28

def check(name)
  if @name_stack.include?(name)
    raise Puppet::DataBinding::RecursiveLookupError, "Recursive lookup detected in [#{@name_stack.join(', ')}]"
  end
  return unless block_given?

  @name_stack.push(name)
  begin
    yield
  rescue Puppet::DataBinding::LookupError
    raise
  rescue Puppet::Error => detail
    raise Puppet::DataBinding::LookupError.new(detail.message, detail)
  ensure
    @name_stack.pop
  end
end

#report_found(key, value) ⇒ Object



91
92
93
94
# File 'lib/puppet/pops/lookup/invocation.rb', line 91

def report_found(key, value)
  @explainer.accept_found(key, value) unless @explainer.nil?
  value
end

#report_found_in_defaults(key, value) ⇒ Object



86
87
88
89
# File 'lib/puppet/pops/lookup/invocation.rb', line 86

def report_found_in_defaults(key, value)
  @explainer.accept_found_in_defaults(key, value) unless @explainer.nil?
  value
end

#report_found_in_overrides(key, value) ⇒ Object



81
82
83
84
# File 'lib/puppet/pops/lookup/invocation.rb', line 81

def report_found_in_overrides(key, value)
  @explainer.accept_found_in_overrides(key, value) unless @explainer.nil?
  value
end

#report_module_not_found ⇒ Object



112
113
114
# File 'lib/puppet/pops/lookup/invocation.rb', line 112

def report_module_not_found
  @explainer.accept_module_not_found unless @explainer.nil?
end

#report_not_found(key) ⇒ Object



104
105
106
# File 'lib/puppet/pops/lookup/invocation.rb', line 104

def report_not_found(key)
  @explainer.accept_not_found(key) unless @explainer.nil?
end

#report_path_not_found ⇒ Object



108
109
110
# File 'lib/puppet/pops/lookup/invocation.rb', line 108

def report_path_not_found
  @explainer.accept_path_not_found unless @explainer.nil?
end

#report_result(value) ⇒ Object

Report the result of a merge or fully resolved interpolated string

Parameters:

  • value (Object) —

    The result to report

Returns:

  • (Object) —

    the given value



99
100
101
102
# File 'lib/puppet/pops/lookup/invocation.rb', line 99

def report_result(value)
  @explainer.accept_result(value) unless @explainer.nil?
  value
end

#with(qualifier_type, qualifier) ⇒ Object

The qualifier_type can be one of: :global - qualifier is the data binding terminus name :data_provider - qualifier a DataProvider instance :path - qualifier is a ResolvedPath instance :merge - qualifier is a MergeStrategy instance :module - qualifier is the name of a module :interpolation - qualifier is the unresolved interpolation expression :meta - qualifier is the name of a module or nil if that's not applicable

Parameters:

  • qualifier (Object) —

    A branch, a provider, or a path



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/puppet/pops/lookup/invocation.rb', line 56

def with(qualifier_type, qualifier)
  is_meta = qualifier_type == :meta
  @module_name = qualifier if is_meta
  if @explainer.nil?
    yield
  else
    if is_meta
      save_explainer = @explainer
      @explainer = nil
      begin
        yield
      ensure
        @explainer = save_explainer
      end
    else
      @explainer.push(qualifier_type, qualifier)
      begin
        yield
      ensure
        @explainer.pop
      end
    end
  end
end