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


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

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)


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

def body
  @body
end

#host_matchesObject (readonly)


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

def host_matches
  @host_matches
end

#parentObject (readonly)


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

def parent
  @parent
end

Class Method Details

._pcore_typeObject


2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
# File 'lib/puppet/pops/model/ast.rb', line 2374

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


2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
# File 'lib/puppet/pops/model/ast.rb', line 2405

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


2395
2396
2397
2398
2399
2400
2401
2402
2403
# File 'lib/puppet/pops/model/ast.rb', line 2395

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


2391
2392
2393
# File 'lib/puppet/pops/model/ast.rb', line 2391

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


2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
# File 'lib/puppet/pops/model/ast.rb', line 2443

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:


2437
2438
2439
2440
2441
# File 'lib/puppet/pops/model/ast.rb', line 2437

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

#_pcore_init_hashObject


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

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


2460
2461
2462
2463
2464
2465
# File 'lib/puppet/pops/model/ast.rb', line 2460

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