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