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

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

Instance Attribute Summary collapse

Class Method 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



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/puppet/pops/lookup/invocation.rb', line 22

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 = DebugExplainer.new(explainer) if Puppet[:debug] && !explainer.is_a?(DebugExplainer)
  @explainer = explainer
end

Instance Attribute Details

#default_valuesObject (readonly)



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

def default_values
  @default_values
end

#explainerObject (readonly)



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

def explainer
  @explainer
end

#module_nameObject



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

def module_name
  @module_name
end

#override_valuesObject (readonly)



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

def override_values
  @override_values
end

#scopeObject (readonly)



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

def scope
  @scope
end

#top_keyObject



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

def top_key
  @top_key
end

Class Method Details

.currentObject



6
7
8
# File 'lib/puppet/pops/lookup/invocation.rb', line 6

def self.current
    nil # TODO, determine how to obtain the current lookup invocation.
end

Instance Method Details

#check(name) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/puppet/pops/lookup/invocation.rb', line 34

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

#emit_debug_info(preamble) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/puppet/pops/lookup/invocation.rb', line 52

def emit_debug_info(preamble)
  debug_explainer = @explainer
  if debug_explainer.is_a?(DebugExplainer)
    @explainer = debug_explainer.wrapped_explainer
    debug_explainer.emit_debug_info(preamble)
  end
end

#explain_options?Boolean

Returns:

  • (Boolean)


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

def explain_options?
  @explainer.nil? ? false : @explainer.explain_options?
end

#only_explain_options?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/puppet/pops/lookup/invocation.rb', line 84

def only_explain_options?
  @explainer.nil? ? false : @explainer.only_explain_options?
end

#report_found(key, value) ⇒ Object



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

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

#report_found_in_defaults(key, value) ⇒ Object



97
98
99
100
# File 'lib/puppet/pops/lookup/invocation.rb', line 97

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



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

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

#report_merge_source(merge_source) ⇒ Object



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

def report_merge_source(merge_source)
  @explainer.accept_merge_source(merge_source) unless @explainer.nil?
end

#report_module_not_foundObject



127
128
129
# File 'lib/puppet/pops/lookup/invocation.rb', line 127

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

#report_not_found(key) ⇒ Object



119
120
121
# File 'lib/puppet/pops/lookup/invocation.rb', line 119

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

#report_path_not_foundObject



123
124
125
# File 'lib/puppet/pops/lookup/invocation.rb', line 123

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



114
115
116
117
# File 'lib/puppet/pops/lookup/invocation.rb', line 114

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

#report_text(&block) ⇒ Object



131
132
133
134
135
# File 'lib/puppet/pops/lookup/invocation.rb', line 131

def report_text(&block)
  unless @explainer.nil?
    @explainer.accept_text(block.call)
  end
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 module name :data - qualifier is the key

Parameters:

  • qualifier (Object)

    A branch, a provider, or a path



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/puppet/pops/lookup/invocation.rb', line 71

def with(qualifier_type, qualifier)
  if @explainer.nil?
    yield
  else
    @explainer.push(qualifier_type, qualifier)
    begin
      yield
    ensure
      @explainer.pop
    end
  end
end