Class: Puppet::Pops::Model::ResourceBody

Inherits:
Positioned 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, title = nil, operations = _pcore_type['operations'].value) ⇒ ResourceBody

Returns a new instance of ResourceBody


4092
4093
4094
4095
4096
4097
# File 'lib/puppet/pops/model/ast.rb', line 4092

def initialize(locator, offset, length, title = nil, operations = _pcore_type['operations'].value)
  super(locator, offset, length)
  @hash = @hash ^ title.hash ^ operations.hash
  @title = title
  @operations = operations
end

Instance Attribute Details

#operationsObject (readonly)


4090
4091
4092
# File 'lib/puppet/pops/model/ast.rb', line 4090

def operations
  @operations
end

#titleObject (readonly)


4089
4090
4091
# File 'lib/puppet/pops/model/ast.rb', line 4089

def title
  @title
end

Class Method Details

._pcore_typeObject


4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
# File 'lib/puppet/pops/model/ast.rb', line 4049

def self._pcore_type
  @_pcore_type ||= Types::PObjectType.new('Puppet::AST::ResourceBody', {
    'parent' => Positioned._pcore_type,
    'attributes' => {
      'title' => {
        'type' => Types::POptionalType.new(Expression._pcore_type),
        'value' => nil
      },
      'operations' => {
        'type' => Types::PArrayType.new(AbstractAttributeOperation._pcore_type),
        'value' => []
      }
    }
  })
end

.create(locator, offset, length, title = nil, operations = _pcore_type['operations'].value) ⇒ Object


4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
# File 'lib/puppet/pops/model/ast.rb', line 4078

def self.create(locator, offset, length, title = nil, operations = _pcore_type['operations'].value)
  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::ResourceBody[title]', attrs['title'].type, title)
  ta.assert_instance_of('Puppet::AST::ResourceBody[operations]', attrs['operations'].type, operations)
  new(locator, offset, length, title, operations)
end

.from_asserted_hash(init_hash) ⇒ Object


4069
4070
4071
4072
4073
4074
4075
4076
# File 'lib/puppet/pops/model/ast.rb', line 4069

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'],
    init_hash['title'],
    init_hash.fetch('operations') { _pcore_type['operations'].value })
end

.from_hash(init_hash) ⇒ Object


4065
4066
4067
# File 'lib/puppet/pops/model/ast.rb', line 4065

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object


4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
# File 'lib/puppet/pops/model/ast.rb', line 4111

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

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

Yields:


4106
4107
4108
4109
# File 'lib/puppet/pops/model/ast.rb', line 4106

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

#_pcore_init_hashObject


4099
4100
4101
4102
4103
4104
# File 'lib/puppet/pops/model/ast.rb', line 4099

def _pcore_init_hash
  result = super
  result['title'] = @title unless @title == nil
  result['operations'] = @operations unless _pcore_type['operations'].default_value?(@operations)
  result
end

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


4124
4125
4126
4127
4128
# File 'lib/puppet/pops/model/ast.rb', line 4124

def eql?(o)
  super &&
  @title.eql?(o.title) &&
  @operations.eql?(o.operations)
end