Class: Puppet::Pops::Model::CaseOption

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

Constructor Details

#initialize(locator, offset, length, values, then_expr = nil) ⇒ CaseOption

Returns a new instance of CaseOption.



1295
1296
1297
1298
1299
1300
# File 'lib/puppet/pops/model/ast.rb', line 1295

def initialize(locator, offset, length, values, then_expr = nil)
  super(locator, offset, length)
  @hash = @hash ^ values.hash ^ then_expr.hash
  @values = values
  @then_expr = then_expr
end

Instance Attribute Details

#then_exprObject (readonly)



1293
1294
1295
# File 'lib/puppet/pops/model/ast.rb', line 1293

def then_expr
  @then_expr
end

#valuesObject (readonly)



1292
1293
1294
# File 'lib/puppet/pops/model/ast.rb', line 1292

def values
  @values
end

Class Method Details

._pcore_typeObject



1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
# File 'lib/puppet/pops/model/ast.rb', line 1253

def self._pcore_type
  @_pcore_type ||=
    Types::PObjectType
      .new('Puppet::AST::CaseOption', {
             'parent' => Expression._pcore_type,
             'attributes' => {
               'values' => Types::PArrayType.new(Expression._pcore_type, Types::PCollectionType::NOT_EMPTY_SIZE),
               'then_expr' => {
                 'type' => Types::POptionalType.new(Expression._pcore_type),
                 'value' => nil
               }
             }
           })
end

.create(locator, offset, length, values, then_expr = nil) ⇒ Object



1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
# File 'lib/puppet/pops/model/ast.rb', line 1281

def self.create(locator, offset, length, values, then_expr = nil)
  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::CaseOption[values]', attrs['values'].type, values)
  ta.assert_instance_of('Puppet::AST::CaseOption[then_expr]', attrs['then_expr'].type, then_expr)
  new(locator, offset, length, values, then_expr)
end

.from_asserted_hash(init_hash) ⇒ Object



1272
1273
1274
1275
1276
1277
1278
1279
# File 'lib/puppet/pops/model/ast.rb', line 1272

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'],
    init_hash['values'],
    init_hash['then_expr'])
end

.from_hash(init_hash) ⇒ Object



1268
1269
1270
# File 'lib/puppet/pops/model/ast.rb', line 1268

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object



1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
# File 'lib/puppet/pops/model/ast.rb', line 1314

def _pcore_all_contents(path, &block)
  path << self
  @values.each do |value|
    block.call(value, path)
    value._pcore_all_contents(path, &block)
  end
  unless @then_expr.nil?
    block.call(@then_expr, path)
    @then_expr._pcore_all_contents(path, &block)
  end
  path.pop
end

#_pcore_contents {|@then_expr| ... } ⇒ Object

Yields:



1309
1310
1311
1312
# File 'lib/puppet/pops/model/ast.rb', line 1309

def _pcore_contents
  @values.each { |value| yield(value) }
  yield(@then_expr) unless @then_expr.nil?
end

#_pcore_init_hashObject



1302
1303
1304
1305
1306
1307
# File 'lib/puppet/pops/model/ast.rb', line 1302

def _pcore_init_hash
  result = super
  result['values'] = @values
  result['then_expr'] = @then_expr unless @then_expr == nil
  result
end

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

Returns:

  • (Boolean)


1327
1328
1329
1330
1331
# File 'lib/puppet/pops/model/ast.rb', line 1327

def eql?(o)
  super &&
  @values.eql?(o.values) &&
  @then_expr.eql?(o.then_expr)
end