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


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

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.


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

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:


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

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.


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

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.


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

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.


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

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.


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

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.


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

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.


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

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.


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

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