Class: Puppet::Pops::Model::BlockExpression

Inherits:
Expression show all
Defined in:
lib/puppet/pops/model/ast.rb

Instance Attribute Summary collapse

Attributes inherited from Positioned

#length, #locator, #offset

Attributes inherited from PopsObject

#hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Positioned

#file, #line, #pos

Methods inherited from PopsObject

#to_s

Methods included from Types::PuppetObject

#_pcore_type

Constructor Details

#initialize(locator, offset, length, statements = _pcore_type['statements'].value) ⇒ BlockExpression

Returns a new instance of BlockExpression.



1187
1188
1189
1190
1191
# File 'lib/puppet/pops/model/ast.rb', line 1187

def initialize(locator, offset, length, statements = _pcore_type['statements'].value)
  super(locator, offset, length)
  @hash = @hash ^ statements.hash
  @statements = statements
end

Instance Attribute Details

#statementsObject (readonly)



1185
1186
1187
# File 'lib/puppet/pops/model/ast.rb', line 1185

def statements
  @statements
end

Class Method Details

._pcore_typeObject



1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
# File 'lib/puppet/pops/model/ast.rb', line 1151

def self._pcore_type
  @_pcore_type ||= Types::PObjectType.new('Puppet::AST::BlockExpression', {
    'parent' => Expression._pcore_type,
    'attributes' => {
      'statements' => {
        'type' => Types::PArrayType.new(Expression._pcore_type),
        'value' => []
      }
    }
  })
end

.create(locator, offset, length, statements = _pcore_type['statements'].value) ⇒ Object



1175
1176
1177
1178
1179
1180
1181
1182
1183
# File 'lib/puppet/pops/model/ast.rb', line 1175

def self.create(locator, offset, length, statements = _pcore_type['statements'].value)
  ta = Types::TypeAsserter
  attrs = _pcore_type.attributes(true)
  ta.assert_instance_of('Puppet::AST::Positioned[locator]', attrs['locator'].type, locator)
  ta.assert_instance_of('Puppet::AST::Positioned[offset]', attrs['offset'].type, offset)
  ta.assert_instance_of('Puppet::AST::Positioned[length]', attrs['length'].type, length)
  ta.assert_instance_of('Puppet::AST::BlockExpression[statements]', attrs['statements'].type, statements)
  new(locator, offset, length, statements)
end

.from_asserted_hash(init_hash) ⇒ Object



1167
1168
1169
1170
1171
1172
1173
# File 'lib/puppet/pops/model/ast.rb', line 1167

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'],
    init_hash.fetch('statements') { _pcore_type['statements'].value })
end

.from_hash(init_hash) ⇒ Object



1163
1164
1165
# File 'lib/puppet/pops/model/ast.rb', line 1163

def self.from_hash(init_hash)
  from_asserted_hash(Types::TypeAsserter.assert_instance_of('Puppet::AST::BlockExpression initializer', _pcore_type.init_hash_type, init_hash))
end

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object



1203
1204
1205
1206
1207
1208
1209
1210
# File 'lib/puppet/pops/model/ast.rb', line 1203

def _pcore_all_contents(path, &block)
  path << self
  @statements.each do |value|
    block.call(value, path)
    value._pcore_all_contents(path, &block)
  end
  path.pop
end

#_pcore_contentsObject



1199
1200
1201
# File 'lib/puppet/pops/model/ast.rb', line 1199

def _pcore_contents
  @statements.each { |value| yield(value) }
end

#_pcore_init_hashObject



1193
1194
1195
1196
1197
# File 'lib/puppet/pops/model/ast.rb', line 1193

def _pcore_init_hash
  result = super
  result['statements'] = @statements unless _pcore_type['statements'].default_value?(@statements)
  result
end

#eql?(o) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


1212
1213
1214
1215
# File 'lib/puppet/pops/model/ast.rb', line 1212

def eql?(o)
  super &&
  @statements.eql?(o.statements)
end