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.



126
127
128
129
# File 'lib/puppet/parser/scope.rb', line 126

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

Instance Attribute Details

#match_dataObject



124
125
126
# File 'lib/puppet/parser/scope.rb', line 124

def match_data
  @match_data
end

Instance Method Details

#[](name) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/puppet/parser/scope.rb', line 135

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

#[]=(name, value) ⇒ Object

Raises:



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

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

#add_entries_to(target = {}, include_undef = false) ⇒ Object



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

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

#bound?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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:



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

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

#include?(name) ⇒ Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/puppet/parser/scope.rb', line 143

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

#is_local_scope?Boolean

Returns:

  • (Boolean)


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

def is_local_scope?
  false
end