Class: Puppet::Pops::Model::HostClassDefinition

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

Instance Attribute Summary collapse

Attributes inherited from NamedDefinition

#body, #name, #parameters

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, parameters = _pcore_type['parameters'].value, body = nil, parent_class = nil) ⇒ HostClassDefinition

Returns a new instance of HostClassDefinition.



2619
2620
2621
2622
2623
# File 'lib/puppet/pops/model/ast.rb', line 2619

def initialize(locator, offset, length, name, parameters = _pcore_type['parameters'].value, body = nil, parent_class = nil)
  super(locator, offset, length, name, parameters, body)
  @hash = @hash ^ parent_class.hash
  @parent_class = parent_class
end

Instance Attribute Details

#parent_classObject (readonly)



2617
2618
2619
# File 'lib/puppet/pops/model/ast.rb', line 2617

def parent_class
  @parent_class
end

Class Method Details

._pcore_typeObject



2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
# File 'lib/puppet/pops/model/ast.rb', line 2575

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

.create(locator, offset, length, name, parameters = _pcore_type['parameters'].value, body = nil, parent_class = nil) ⇒ Object



2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
# File 'lib/puppet/pops/model/ast.rb', line 2604

def self.create(locator, offset, length, name, parameters = _pcore_type['parameters'].value, body = nil, parent_class = 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::NamedDefinition[name]', attrs['name'].type, name)
  ta.assert_instance_of('Puppet::AST::NamedDefinition[parameters]', attrs['parameters'].type, parameters)
  ta.assert_instance_of('Puppet::AST::NamedDefinition[body]', attrs['body'].type, body)
  ta.assert_instance_of('Puppet::AST::HostClassDefinition[parent_class]', attrs['parent_class'].type, parent_class)
  new(locator, offset, length, name, parameters, body, parent_class)
end

.from_asserted_hash(init_hash) ⇒ Object



2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
# File 'lib/puppet/pops/model/ast.rb', line 2593

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'],
    init_hash['name'],
    init_hash.fetch('parameters') { _pcore_type['parameters'].value },
    init_hash['body'],
    init_hash['parent_class'])
end

.from_hash(init_hash) ⇒ Object



2589
2590
2591
# File 'lib/puppet/pops/model/ast.rb', line 2589

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object



2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
# File 'lib/puppet/pops/model/ast.rb', line 2636

def _pcore_all_contents(path, &block)
  path << self
  @parameters.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 {|@body| ... } ⇒ Object

Yields:



2631
2632
2633
2634
# File 'lib/puppet/pops/model/ast.rb', line 2631

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

#_pcore_init_hashObject



2625
2626
2627
2628
2629
# File 'lib/puppet/pops/model/ast.rb', line 2625

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

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

Returns:

  • (Boolean)


2649
2650
2651
2652
# File 'lib/puppet/pops/model/ast.rb', line 2649

def eql?(o)
  super &&
  @parent_class.eql?(o.parent_class)
end