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

Constructor Details

#initialize(locator, offset, length, host_matches, parent = nil, body = nil) ⇒ NodeDefinition

Returns a new instance of NodeDefinition.



2448
2449
2450
2451
2452
2453
2454
# File 'lib/puppet/pops/model/ast.rb', line 2448

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)



2446
2447
2448
# File 'lib/puppet/pops/model/ast.rb', line 2446

def body
  @body
end

#host_matchesObject (readonly)



2445
2446
2447
# File 'lib/puppet/pops/model/ast.rb', line 2445

def host_matches
  @host_matches
end

#parentObject (readonly)



2444
2445
2446
# File 'lib/puppet/pops/model/ast.rb', line 2444

def parent
  @parent
end

Class Method Details

._pcore_typeObject



2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
# File 'lib/puppet/pops/model/ast.rb', line 2399

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



2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
# File 'lib/puppet/pops/model/ast.rb', line 2432

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



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

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



2418
2419
2420
# File 'lib/puppet/pops/model/ast.rb', line 2418

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



2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
# File 'lib/puppet/pops/model/ast.rb', line 2470

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:



2464
2465
2466
2467
2468
# File 'lib/puppet/pops/model/ast.rb', line 2464

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

#_pcore_init_hashObject



2456
2457
2458
2459
2460
2461
2462
# File 'lib/puppet/pops/model/ast.rb', line 2456

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)


2487
2488
2489
2490
2491
2492
# File 'lib/puppet/pops/model/ast.rb', line 2487

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