Class: Puppet::Parser::Scope::ParameterScope Private

Inherits:
Ephemeral show all
Defined in:
lib/puppet/parser/scope.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: Access

Instance Attribute Summary

Attributes inherited from Ephemeral

#parent

Instance Method Summary collapse

Methods inherited from Ephemeral

#add_entries_to

Constructor Details

#initialize(parent, callee_name, param_names) ⇒ ParameterScope

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ParameterScope.



223
224
225
226
227
228
# File 'lib/puppet/parser/scope.rb', line 223

def initialize(parent, callee_name, param_names)
  super(parent)
  @callee_name = callee_name
  @params = {}
  param_names.each { |name| @params[name] = Access.new }
end

Instance Method Details

#[](name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



230
231
232
233
234
235
# File 'lib/puppet/parser/scope.rb', line 230

def [](name)
  access = @params[name]
  return super if access.nil?
  throw(:unevaluated_parameter, name) unless access.assigned?
  access.value
end

#[]=(name, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:



237
238
239
240
241
# File 'lib/puppet/parser/scope.rb', line 237

def []=(name, value)
  raise Puppet::Error, _("Attempt to assign variable %{name} when evaluating parameters") % { name: name } if @read_only
  @params[name] ||= Access.new
  @params[name].value = value
end

#as_read_onlyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



255
256
257
258
259
260
261
262
263
# File 'lib/puppet/parser/scope.rb', line 255

def as_read_only
  read_only = @read_only
  @read_only = true
  begin
    yield
  ensure
    @read_only = read_only
  end
end

#bound?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


243
244
245
# File 'lib/puppet/parser/scope.rb', line 243

def bound?(name)
  @params.include?(name)
end

#evaluate(name, expression, scope, evaluator) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



205
206
207
208
209
210
211
212
213
# File 'lib/puppet/parser/scope.rb', line 205

def evaluate(name, expression, scope, evaluator)
  scope.with_guarded_scope do
    bad = catch(:unevaluated_parameter) do
      scope.new_match_scope(nil)
      return as_read_only { evaluator.evaluate(expression, scope) }
    end
    parameter_reference_failure(name, bad)
  end
end

#evaluate3x(name, expression, scope) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A parameter default must be evaluated using a special scope. The scope that is given to this method must have a ‘ParameterScope` as its last ephemeral scope. This method will then push a `MatchScope` while the given `expression` is evaluated. The method will catch any throw of `:unevaluated_parameter` and produce an error saying that the evaluated parameter X tries to access the unevaluated parameter Y.

Parameters:

  • name (String)

    the name of the currently evaluated parameter

  • expression (Puppet::Parser::AST)

    the expression to evaluate

  • scope (Puppet::Parser::Scope)

    a scope where a ‘ParameterScope` has been pushed

Returns:

  • (Object)

    the result of the evaluation



195
196
197
198
199
200
201
202
203
# File 'lib/puppet/parser/scope.rb', line 195

def evaluate3x(name, expression, scope)
  scope.with_guarded_scope do
    bad = catch(:unevaluated_parameter) do
      scope.new_match_scope(nil)
      return as_read_only { expression.safeevaluate(scope) }
    end
    parameter_reference_failure(name, bad)
  end
end

#include?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


247
248
249
# File 'lib/puppet/parser/scope.rb', line 247

def include?(name)
  @params.include?(name) || super
end

#is_local_scope?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


251
252
253
# File 'lib/puppet/parser/scope.rb', line 251

def is_local_scope?
  true
end

#to_hashObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



265
266
267
# File 'lib/puppet/parser/scope.rb', line 265

def to_hash
  Hash[@params.select {|_, access| access.assigned? }.map { |name, access| [name, access.value] }]
end