Class: Puppet::Parser::Scope::MatchScope

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

Instance Attribute Summary collapse

Attributes inherited from Ephemeral

#parent

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, match_data = nil) ⇒ MatchScope

Returns a new instance of MatchScope.



132
133
134
135
# File 'lib/puppet/parser/scope.rb', line 132

def initialize(parent = nil, match_data = nil)
  super parent
  @match_data = match_data
end

Instance Attribute Details

#match_dataObject



130
131
132
# File 'lib/puppet/parser/scope.rb', line 130

def match_data
  @match_data
end

Instance Method Details

#[](name) ⇒ Object



141
142
143
144
145
146
147
# File 'lib/puppet/parser/scope.rb', line 141

def [](name)
  if bound?(name)
    @match_data[name.to_i]
  else
    super
  end
end

#[]=(name, value) ⇒ Object

Raises:



160
161
162
163
# File 'lib/puppet/parser/scope.rb', line 160

def []=(name, value)
  # TODO: Bad choice of exception
  raise Puppet::ParseError, "Numerical variables cannot be changed. Attempt to set $#{name}"
end

#add_entries_to(target = {}) ⇒ Object



170
171
172
173
# File 'lib/puppet/parser/scope.rb', line 170

def add_entries_to(target = {})
  # do not include match data ($0-$n)
  super
end

#bound?(name) ⇒ Boolean

Returns:

  • (Boolean)


153
154
155
156
157
158
# File 'lib/puppet/parser/scope.rb', line 153

def bound?(name)
  # A "match variables" scope reports all numeric variables to be bound if the scope has
  # match_data. Without match data the scope is transparent.
  #
  @match_data && name =~ /^\d+$/
end

#delete(name) ⇒ Object

Raises:



165
166
167
168
# File 'lib/puppet/parser/scope.rb', line 165

def delete(name)
  # TODO: Bad choice of exception
  raise Puppet::ParseError, "Numerical variables cannot be deleted: Attempt to delete: $#{name}"
end

#include?(name) ⇒ Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/puppet/parser/scope.rb', line 149

def include?(name)
  bound?(name) or super
end

#is_local_scope?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/puppet/parser/scope.rb', line 137

def is_local_scope?
  false
end