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

Constructor Details

#initialize(locator, offset, length, name, parent = nil, body = nil) ⇒ TypeDefinition

Returns a new instance of TypeDefinition


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

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)


2336
2337
2338
# File 'lib/puppet/pops/model/ast.rb', line 2336

def body
  @body
end

#parentObject (readonly)


2335
2336
2337
# File 'lib/puppet/pops/model/ast.rb', line 2335

def parent
  @parent
end

Class Method Details

._pcore_typeObject


2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
# File 'lib/puppet/pops/model/ast.rb', line 2293

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


2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
# File 'lib/puppet/pops/model/ast.rb', line 2323

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


2313
2314
2315
2316
2317
2318
2319
2320
2321
# File 'lib/puppet/pops/model/ast.rb', line 2313

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


2309
2310
2311
# File 'lib/puppet/pops/model/ast.rb', line 2309

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


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

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:


2352
2353
2354
# File 'lib/puppet/pops/model/ast.rb', line 2352

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

#_pcore_init_hashObject


2345
2346
2347
2348
2349
2350
# File 'lib/puppet/pops/model/ast.rb', line 2345

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


2365
2366
2367
2368
2369
# File 'lib/puppet/pops/model/ast.rb', line 2365

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