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

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

Direct Known Subclasses

ApplyBlockExpression

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, #to_s

Constructor Details

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

Returns a new instance of BlockExpression.



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

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)



1210
1211
1212
# File 'lib/puppet/pops/model/ast.rb', line 1210

def statements
  @statements
end

Class Method Details

._pcore_typeObject



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

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



1200
1201
1202
1203
1204
1205
1206
1207
1208
# File 'lib/puppet/pops/model/ast.rb', line 1200

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



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

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



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

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



1228
1229
1230
1231
1232
1233
1234
1235
# File 'lib/puppet/pops/model/ast.rb', line 1228

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



1224
1225
1226
# File 'lib/puppet/pops/model/ast.rb', line 1224

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

#_pcore_init_hashObject



1218
1219
1220
1221
1222
# File 'lib/puppet/pops/model/ast.rb', line 1218

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)


1237
1238
1239
1240
# File 'lib/puppet/pops/model/ast.rb', line 1237

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