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.


1269
1270
1271
1272
1273
1274
# File 'lib/puppet/pops/model/ast.rb', line 1269

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)


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

def then_expr
  @then_expr
end

#valuesObject (readonly)


1266
1267
1268
# File 'lib/puppet/pops/model/ast.rb', line 1266

def values
  @values
end

Class Method Details

._pcore_typeObject


1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
# File 'lib/puppet/pops/model/ast.rb', line 1229

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


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

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


1246
1247
1248
1249
1250
1251
1252
1253
# File 'lib/puppet/pops/model/ast.rb', line 1246

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


1242
1243
1244
# File 'lib/puppet/pops/model/ast.rb', line 1242

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


1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
# File 'lib/puppet/pops/model/ast.rb', line 1288

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:


1283
1284
1285
1286
# File 'lib/puppet/pops/model/ast.rb', line 1283

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

#_pcore_init_hashObject


1276
1277
1278
1279
1280
1281
# File 'lib/puppet/pops/model/ast.rb', line 1276

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)

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

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