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:



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

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)



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

def attributes
  @attributes
end

#locationObject (readonly)



206
207
208
# File 'lib/puppet_x/puppetlabs/migration/catalog_delta_model.rb', line 206

def location
  @location
end

#titleObject (readonly)



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

def title
  @title
end

#typeObject (readonly)



211
212
213
# File 'lib/puppet_x/puppetlabs/migration/catalog_delta_model.rb', line 211

def type
  @type
end

Instance Method Details

#assign_ids(start) ⇒ Object



247
248
249
250
# File 'lib/puppet_x/puppetlabs/migration/catalog_delta_model.rb', line 247

def assign_ids(start)
  @attributes = @attributes.values if @attributes.is_a?(Hash)
  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



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

def clear_attributes
  @attributes = nil
end

#initialize_from_hash(hash) ⇒ Object



260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/puppet_x/puppetlabs/migration/catalog_delta_model.rb', line 260

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



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

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