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.


220
221
222
223
224
225
# File 'lib/puppet/parser/scope.rb', line 220

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.


227
228
229
230
231
232
# File 'lib/puppet/parser/scope.rb', line 227

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:


234
235
236
237
238
# File 'lib/puppet/parser/scope.rb', line 234

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.


252
253
254
255
256
257
258
259
260
# File 'lib/puppet/parser/scope.rb', line 252

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)

240
241
242
# File 'lib/puppet/parser/scope.rb', line 240

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.


202
203
204
205
206
207
208
209
210
# File 'lib/puppet/parser/scope.rb', line 202

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


192
193
194
195
196
197
198
199
200
# File 'lib/puppet/parser/scope.rb', line 192

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)

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

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)

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

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.


262
263
264
# File 'lib/puppet/parser/scope.rb', line 262

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