Class: PuppetX::Puppetlabs::Migration::CatalogDeltaModel::Resource

Inherits:
Diff
  • Object
show all
Defined in:
lib/puppet_x/puppetlabs/migration/catalog_delta_model.rb

Overview

Represents a resource in the Catalog.

Instance Attribute Summary collapse

Attributes inherited from Diff

#diff_id

Instance Method Summary collapse

Methods inherited from DeltaEntity

from_hash

Methods included from ModelObject

#to_hash

Constructor Details

#initialize(location, type, title, attributes) ⇒ Resource

Returns a new instance of Resource.

Parameters:

  • location (Location)
  • type (String)
  • title (String)
  • attributes (Hash<String,Attribute>)


240
241
242
243
244
245
# File 'lib/puppet_x/puppetlabs/migration/catalog_delta_model.rb', line 240

def initialize(location, type, title, attributes)
  @location = location
  @type = assert_type(String, type)
  @title = assert_type(String, title)
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)



234
235
236
# File 'lib/puppet_x/puppetlabs/migration/catalog_delta_model.rb', line 234

def attributes
  @attributes
end

#locationObject (readonly)



215
216
217
# File 'lib/puppet_x/puppetlabs/migration/catalog_delta_model.rb', line 215

def location
  @location
end

#titleObject (readonly)



225
226
227
# File 'lib/puppet_x/puppetlabs/migration/catalog_delta_model.rb', line 225

def title
  @title
end

#typeObject (readonly)



220
221
222
# File 'lib/puppet_x/puppetlabs/migration/catalog_delta_model.rb', line 220

def type
  @type
end

Instance Method Details

#assign_ids(start) ⇒ Object



256
257
258
# File 'lib/puppet_x/puppetlabs/migration/catalog_delta_model.rb', line 256

def assign_ids(start)
  assign_ids_on_each(super(start), @attributes)
end

#clear_attributesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set the attributes instance variable to ‘nil`. This is done for all resources in the delta unless the production is flagged as verbose



264
265
266
# File 'lib/puppet_x/puppetlabs/migration/catalog_delta_model.rb', line 264

def clear_attributes
  @attributes = nil
end

#finish_attributesObject



268
269
270
# File 'lib/puppet_x/puppetlabs/migration/catalog_delta_model.rb', line 268

def finish_attributes
  @attributes = @attributes.values.each { |v| v.finish } if @attributes.is_a?(Hash)
end

#initialize_from_hash(hash) ⇒ Object



272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/puppet_x/puppetlabs/migration/catalog_delta_model.rb', line 272

def initialize_from_hash(hash)
  hash.each_pair do |k, v|
    k = :"@#{k}"
    instance_variable_set(k,
      case k
      when :@location
        Location.from_hash(v)
      when :@attributes
        v.map { |rh| Attribute.from_hash(rh) }
      else
        v
      end)
  end
end

#keyString

Returns the key that uniquely identifies the Resource. The key is used when finding added, missing, equal, and conflicting resources in the compared catalogs.

Returns:

  • (String)

    resource key constructed from type and title



252
253
254
# File 'lib/puppet_x/puppetlabs/migration/catalog_delta_model.rb', line 252

def key
  "#{@type}{#{@title}}]"
end