Class: Puppet::Pops::Model::ResourceExpression

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

Instance Attribute Summary collapse

Attributes inherited from AbstractResource

#form

Attributes inherited from Positioned

#length, #locator, #offset

Attributes inherited from PopsObject

#hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractResource

#exported, #virtual

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, type_name, form = "regular", bodies = _pcore_type['bodies'].value) ⇒ ResourceExpression

Returns a new instance of ResourceExpression


4247
4248
4249
4250
4251
4252
# File 'lib/puppet/pops/model/ast.rb', line 4247

def initialize(locator, offset, length, type_name, form = "regular", bodies = _pcore_type['bodies'].value)
  super(locator, offset, length, form)
  @hash = @hash ^ type_name.hash ^ bodies.hash
  @type_name = type_name
  @bodies = bodies
end

Instance Attribute Details

#bodiesObject (readonly)


4245
4246
4247
# File 'lib/puppet/pops/model/ast.rb', line 4245

def bodies
  @bodies
end

#type_nameObject (readonly)


4244
4245
4246
# File 'lib/puppet/pops/model/ast.rb', line 4244

def type_name
  @type_name
end

Class Method Details

._pcore_typeObject


4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
# File 'lib/puppet/pops/model/ast.rb', line 4205

def self._pcore_type
  @_pcore_type ||= Types::PObjectType.new('Puppet::AST::ResourceExpression', {
    'parent' => AbstractResource._pcore_type,
    'attributes' => {
      'type_name' => Expression._pcore_type,
      'bodies' => {
        'type' => Types::PArrayType.new(ResourceBody._pcore_type),
        'value' => []
      }
    }
  })
end

.create(locator, offset, length, type_name, form = "regular", bodies = _pcore_type['bodies'].value) ⇒ Object


4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
# File 'lib/puppet/pops/model/ast.rb', line 4232

def self.create(locator, offset, length, type_name, form = "regular", bodies = _pcore_type['bodies'].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::AbstractResource[form]', attrs['form'].type, form)
  ta.assert_instance_of('Puppet::AST::ResourceExpression[type_name]', attrs['type_name'].type, type_name)
  ta.assert_instance_of('Puppet::AST::ResourceExpression[bodies]', attrs['bodies'].type, bodies)
  new(locator, offset, length, type_name, form, bodies)
end

.from_asserted_hash(init_hash) ⇒ Object


4222
4223
4224
4225
4226
4227
4228
4229
4230
# File 'lib/puppet/pops/model/ast.rb', line 4222

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'],
    init_hash['type_name'],
    init_hash.fetch('form') { "regular" },
    init_hash.fetch('bodies') { _pcore_type['bodies'].value })
end

.from_hash(init_hash) ⇒ Object


4218
4219
4220
# File 'lib/puppet/pops/model/ast.rb', line 4218

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object


4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
# File 'lib/puppet/pops/model/ast.rb', line 4266

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

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

Yields:


4261
4262
4263
4264
# File 'lib/puppet/pops/model/ast.rb', line 4261

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

#_pcore_init_hashObject


4254
4255
4256
4257
4258
4259
# File 'lib/puppet/pops/model/ast.rb', line 4254

def _pcore_init_hash
  result = super
  result['type_name'] = @type_name
  result['bodies'] = @bodies unless _pcore_type['bodies'].default_value?(@bodies)
  result
end

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


4279
4280
4281
4282
4283
# File 'lib/puppet/pops/model/ast.rb', line 4279

def eql?(o)
  super &&
  @type_name.eql?(o.type_name) &&
  @bodies.eql?(o.bodies)
end