Class: Puppet::Pops::Model::TypeDefinition

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

Instance Attribute Summary collapse

Attributes inherited from QRefDefinition

#name

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, name, parent = nil, body = nil) ⇒ TypeDefinition

Returns a new instance of TypeDefinition.



2330
2331
2332
2333
2334
2335
# File 'lib/puppet/pops/model/ast.rb', line 2330

def initialize(locator, offset, length, name, parent = nil, body = nil)
  super(locator, offset, length, name)
  @hash = @hash ^ parent.hash ^ body.hash
  @parent = parent
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)



2328
2329
2330
# File 'lib/puppet/pops/model/ast.rb', line 2328

def body
  @body
end

#parentObject (readonly)



2327
2328
2329
# File 'lib/puppet/pops/model/ast.rb', line 2327

def parent
  @parent
end

Class Method Details

._pcore_typeObject



2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
# File 'lib/puppet/pops/model/ast.rb', line 2285

def self._pcore_type
  @_pcore_type ||= Types::PObjectType.new('Puppet::AST::TypeDefinition', {
    'parent' => QRefDefinition._pcore_type,
    'attributes' => {
      'parent' => {
        'type' => Types::POptionalType.new(Types::PStringType::DEFAULT),
        'value' => nil
      },
      'body' => {
        'type' => Types::POptionalType.new(Expression._pcore_type),
        'value' => nil
      }
    }
  })
end

.create(locator, offset, length, name, parent = nil, body = nil) ⇒ Object



2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
# File 'lib/puppet/pops/model/ast.rb', line 2315

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

.from_asserted_hash(init_hash) ⇒ Object



2305
2306
2307
2308
2309
2310
2311
2312
2313
# File 'lib/puppet/pops/model/ast.rb', line 2305

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'],
    init_hash['name'],
    init_hash['parent'],
    init_hash['body'])
end

.from_hash(init_hash) ⇒ Object



2301
2302
2303
# File 'lib/puppet/pops/model/ast.rb', line 2301

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object



2348
2349
2350
2351
2352
2353
2354
2355
# File 'lib/puppet/pops/model/ast.rb', line 2348

def _pcore_all_contents(path, &block)
  path << self
  unless @body.nil?
    block.call(@body, path)
    @body._pcore_all_contents(path, &block)
  end
  path.pop
end

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

Yields:



2344
2345
2346
# File 'lib/puppet/pops/model/ast.rb', line 2344

def _pcore_contents
  yield(@body) unless @body.nil?
end

#_pcore_init_hashObject



2337
2338
2339
2340
2341
2342
# File 'lib/puppet/pops/model/ast.rb', line 2337

def _pcore_init_hash
  result = super
  result['parent'] = @parent unless @parent == nil
  result['body'] = @body unless @body == nil
  result
end

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

Returns:

  • (Boolean)


2357
2358
2359
2360
2361
# File 'lib/puppet/pops/model/ast.rb', line 2357

def eql?(o)
  super &&
  @parent.eql?(o.parent) &&
  @body.eql?(o.body)
end