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

Constructor Details

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

Returns a new instance of CaseOption.



1260
1261
1262
1263
1264
1265
# File 'lib/puppet/pops/model/ast.rb', line 1260

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)



1258
1259
1260
# File 'lib/puppet/pops/model/ast.rb', line 1258

def then_expr
  @then_expr
end

#valuesObject (readonly)



1257
1258
1259
# File 'lib/puppet/pops/model/ast.rb', line 1257

def values
  @values
end

Class Method Details

._pcore_typeObject



1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
# File 'lib/puppet/pops/model/ast.rb', line 1220

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



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

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



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

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



1233
1234
1235
# File 'lib/puppet/pops/model/ast.rb', line 1233

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



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

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:



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

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

#_pcore_init_hashObject



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

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)


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

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