class Puppet::Parser::Scope::ParameterScope
@api private
Public Class Methods
new(parent, callee_name, param_names)
click to toggle source
Calls superclass method
Puppet::Parser::Scope::Ephemeral::new
# File lib/puppet/parser/scope.rb 220 def initialize(parent, callee_name, param_names) 221 super(parent) 222 @callee_name = callee_name 223 @params = {} 224 param_names.each { |name| @params[name] = Access.new } 225 end
Public Instance Methods
[](name)
click to toggle source
Calls superclass method
Puppet::Parser::Scope::Ephemeral#[]
# File lib/puppet/parser/scope.rb 227 def [](name) 228 access = @params[name] 229 return super if access.nil? 230 throw(:unevaluated_parameter, name) unless access.assigned? 231 access.value 232 end
[]=(name, value)
click to toggle source
# File lib/puppet/parser/scope.rb 234 def []=(name, value) 235 raise Puppet::Error, _("Attempt to assign variable %{name} when evaluating parameters") % { name: name } if @read_only 236 @params[name] ||= Access.new 237 @params[name].value = value 238 end
as_read_only() { || ... }
click to toggle source
# File lib/puppet/parser/scope.rb 252 def as_read_only 253 read_only = @read_only 254 @read_only = true 255 begin 256 yield 257 ensure 258 @read_only = read_only 259 end 260 end
bound?(name)
click to toggle source
# File lib/puppet/parser/scope.rb 240 def bound?(name) 241 @params.include?(name) 242 end
evaluate(name, expression, scope, evaluator)
click to toggle source
# File lib/puppet/parser/scope.rb 202 def evaluate(name, expression, scope, evaluator) 203 scope.with_guarded_scope do 204 bad = catch(:unevaluated_parameter) do 205 scope.new_match_scope(nil) 206 return as_read_only { evaluator.evaluate(expression, scope) } 207 end 208 parameter_reference_failure(name, bad) 209 end 210 end
evaluate3x(name, expression, scope)
click to toggle source
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.
@param name [String] the name of the currently evaluated parameter @param expression [Puppet::Parser::AST] the expression to evaluate @param scope [Puppet::Parser::Scope] a scope where a `ParameterScope` has been pushed @return [Object] the result of the evaluation
@api private
# File lib/puppet/parser/scope.rb 192 def evaluate3x(name, expression, scope) 193 scope.with_guarded_scope do 194 bad = catch(:unevaluated_parameter) do 195 scope.new_match_scope(nil) 196 return as_read_only { expression.safeevaluate(scope) } 197 end 198 parameter_reference_failure(name, bad) 199 end 200 end
include?(name)
click to toggle source
Calls superclass method
Puppet::Parser::Scope::Ephemeral#include?
# File lib/puppet/parser/scope.rb 244 def include?(name) 245 @params.include?(name) || super 246 end
is_local_scope?()
click to toggle source
# File lib/puppet/parser/scope.rb 248 def is_local_scope? 249 true 250 end
to_hash()
click to toggle source
# File lib/puppet/parser/scope.rb 262 def to_hash 263 Hash[@params.select {|_, access| access.assigned? }.map { |name, access| [name, access.value] }] 264 end
Private Instance Methods
parameter_reference_failure(from, to)
click to toggle source
# File lib/puppet/parser/scope.rb 212 def parameter_reference_failure(from, to) 213 # Parameters are evaluated in the order they have in the @params hash. 214 keys = @params.keys 215 raise Puppet::Error, _("%{callee}: expects a value for parameter $%{to}") % { callee: @callee_name, to: to } if keys.index(to) < keys.index(from) 216 raise Puppet::Error, _("%{callee}: default expression for $%{from} tries to illegally access not yet evaluated $%{to}") % { callee: @callee_name, from: from, to: to } 217 end