Class: Puppet::Pops::Model::TypeMapping

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, type_expr = nil, mapping_expr = nil) ⇒ TypeMapping

Returns a new instance of TypeMapping.



2275
2276
2277
2278
2279
2280
# File 'lib/puppet/pops/model/ast.rb', line 2275

def initialize(locator, offset, length, type_expr = nil, mapping_expr = nil)
  super(locator, offset, length)
  @hash = @hash ^ type_expr.hash ^ mapping_expr.hash
  @type_expr = type_expr
  @mapping_expr = mapping_expr
end

Instance Attribute Details

#mapping_exprObject (readonly)



2273
2274
2275
# File 'lib/puppet/pops/model/ast.rb', line 2273

def mapping_expr
  @mapping_expr
end

#type_exprObject (readonly)



2272
2273
2274
# File 'lib/puppet/pops/model/ast.rb', line 2272

def type_expr
  @type_expr
end

Class Method Details

._pcore_typeObject



2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
# File 'lib/puppet/pops/model/ast.rb', line 2230

def self._pcore_type
  @_pcore_type ||=
    Types::PObjectType
      .new('Puppet::AST::TypeMapping', {
             'parent' => Definition._pcore_type,
             'attributes' => {
               'type_expr' => {
                 'type' => Types::POptionalType.new(Expression._pcore_type),
                 'value' => nil
               },
               'mapping_expr' => {
                 'type' => Types::POptionalType.new(Expression._pcore_type),
                 'value' => nil
               }
             }
           })
end

.create(locator, offset, length, type_expr = nil, mapping_expr = nil) ⇒ Object



2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
# File 'lib/puppet/pops/model/ast.rb', line 2261

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

.from_asserted_hash(init_hash) ⇒ Object



2252
2253
2254
2255
2256
2257
2258
2259
# File 'lib/puppet/pops/model/ast.rb', line 2252

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'],
    init_hash['type_expr'],
    init_hash['mapping_expr'])
end

.from_hash(init_hash) ⇒ Object



2248
2249
2250
# File 'lib/puppet/pops/model/ast.rb', line 2248

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object



2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
# File 'lib/puppet/pops/model/ast.rb', line 2294

def _pcore_all_contents(path, &block)
  path << self
  unless @type_expr.nil?
    block.call(@type_expr, path)
    @type_expr._pcore_all_contents(path, &block)
  end
  unless @mapping_expr.nil?
    block.call(@mapping_expr, path)
    @mapping_expr._pcore_all_contents(path, &block)
  end
  path.pop
end

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

Yields:



2289
2290
2291
2292
# File 'lib/puppet/pops/model/ast.rb', line 2289

def _pcore_contents
  yield(@type_expr) unless @type_expr.nil?
  yield(@mapping_expr) unless @mapping_expr.nil?
end

#_pcore_init_hashObject



2282
2283
2284
2285
2286
2287
# File 'lib/puppet/pops/model/ast.rb', line 2282

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

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

Returns:

  • (Boolean)


2307
2308
2309
2310
2311
# File 'lib/puppet/pops/model/ast.rb', line 2307

def eql?(o)
  super &&
  @type_expr.eql?(o.type_expr) &&
  @mapping_expr.eql?(o.mapping_expr)
end