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


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

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)


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

def then_expr
  @then_expr
end

#valuesObject (readonly)


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

def values
  @values
end

Class Method Details

._pcore_typeObject


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

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


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

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


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

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


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

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


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

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:


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

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

#_pcore_init_hashObject


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

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: ==


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

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