Class: Puppet::Pops::Model::NodeDefinition

Inherits:
Definition 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, host_matches, parent = nil, body = nil) ⇒ NodeDefinition

Returns a new instance of NodeDefinition.



2413
2414
2415
2416
2417
2418
2419
# File 'lib/puppet/pops/model/ast.rb', line 2413

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

Instance Attribute Details

#bodyObject (readonly)



2411
2412
2413
# File 'lib/puppet/pops/model/ast.rb', line 2411

def body
  @body
end

#host_matchesObject (readonly)



2410
2411
2412
# File 'lib/puppet/pops/model/ast.rb', line 2410

def host_matches
  @host_matches
end

#parentObject (readonly)



2409
2410
2411
# File 'lib/puppet/pops/model/ast.rb', line 2409

def parent
  @parent
end

Class Method Details

._pcore_typeObject



2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
# File 'lib/puppet/pops/model/ast.rb', line 2366

def self._pcore_type
  @_pcore_type ||= Types::PObjectType.new('Puppet::AST::NodeDefinition', {
    'parent' => Definition._pcore_type,
    'attributes' => {
      'parent' => {
        'type' => Types::POptionalType.new(Expression._pcore_type),
        'value' => nil
      },
      'host_matches' => Types::PArrayType.new(Expression._pcore_type, Types::PCollectionType::NOT_EMPTY_SIZE),
      'body' => {
        'type' => Types::POptionalType.new(Expression._pcore_type),
        'value' => nil
      }
    }
  })
end

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



2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
# File 'lib/puppet/pops/model/ast.rb', line 2397

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

.from_asserted_hash(init_hash) ⇒ Object



2387
2388
2389
2390
2391
2392
2393
2394
2395
# File 'lib/puppet/pops/model/ast.rb', line 2387

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

.from_hash(init_hash) ⇒ Object



2383
2384
2385
# File 'lib/puppet/pops/model/ast.rb', line 2383

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object



2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
# File 'lib/puppet/pops/model/ast.rb', line 2435

def _pcore_all_contents(path, &block)
  path << self
  unless @parent.nil?
    block.call(@parent, path)
    @parent._pcore_all_contents(path, &block)
  end
  @host_matches.each do |value|
    block.call(value, path)
    value._pcore_all_contents(path, &block)
  end
  unless @body.nil?
    block.call(@body, path)
    @body._pcore_all_contents(path, &block)
  end
  path.pop
end

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

Yields:



2429
2430
2431
2432
2433
# File 'lib/puppet/pops/model/ast.rb', line 2429

def _pcore_contents
  yield(@parent) unless @parent.nil?
  @host_matches.each { |value| yield(value) }
  yield(@body) unless @body.nil?
end

#_pcore_init_hashObject



2421
2422
2423
2424
2425
2426
2427
# File 'lib/puppet/pops/model/ast.rb', line 2421

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

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

Returns:

  • (Boolean)


2452
2453
2454
2455
2456
2457
# File 'lib/puppet/pops/model/ast.rb', line 2452

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