Class: Hawkular::Inventory::CanonicalPath

Inherits:
Object
  • Object
show all
Defined in:
lib/hawkular/inventory/entities.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ CanonicalPath

Returns a new instance of CanonicalPath



169
170
171
172
173
174
175
176
177
# File 'lib/hawkular/inventory/entities.rb', line 169

def initialize(hash)
  @tenant_id = hash[:tenant_id]
  @feed_id = hash[:feed_id]
  @environment_id = hash[:environment_id]
  @resource_type_id = hash[:resource_type_id]
  @metric_type_id = hash[:metric_type_id]
  @resource_ids = hash[:resource_ids]
  @metric_id = hash[:metric_id]
end

Instance Attribute Details

#environment_idObject (readonly)

Returns the value of attribute environment_id



163
164
165
# File 'lib/hawkular/inventory/entities.rb', line 163

def environment_id
  @environment_id
end

#feed_idObject (readonly)

Returns the value of attribute feed_id



162
163
164
# File 'lib/hawkular/inventory/entities.rb', line 162

def feed_id
  @feed_id
end

#metric_idObject (readonly)

Returns the value of attribute metric_id



165
166
167
# File 'lib/hawkular/inventory/entities.rb', line 165

def metric_id
  @metric_id
end

#metric_type_idObject (readonly)

Returns the value of attribute metric_type_id



167
168
169
# File 'lib/hawkular/inventory/entities.rb', line 167

def metric_type_id
  @metric_type_id
end

#resource_idsObject (readonly)

Returns the value of attribute resource_ids



164
165
166
# File 'lib/hawkular/inventory/entities.rb', line 164

def resource_ids
  @resource_ids
end

#resource_type_idObject (readonly)

Returns the value of attribute resource_type_id



166
167
168
# File 'lib/hawkular/inventory/entities.rb', line 166

def resource_type_id
  @resource_type_id
end

#tenant_idObject (readonly)

Returns the value of attribute tenant_id



161
162
163
# File 'lib/hawkular/inventory/entities.rb', line 161

def tenant_id
  @tenant_id
end

Class Method Details

.parse(path) ⇒ Object



179
180
181
182
# File 'lib/hawkular/inventory/entities.rb', line 179

def self.parse(path)
  fail 'CanonicalPath must not be nil or empty' if path.to_s.strip.length == 0
  CanonicalPath.new(path_to_h path)
end

Instance Method Details

#==(other) ⇒ Object



205
206
207
# File 'lib/hawkular/inventory/entities.rb', line 205

def ==(other)
  self.equal?(other) || other.class == self.class && other.state == state
end

#to_hObject



209
210
211
212
213
214
215
216
217
218
219
# File 'lib/hawkular/inventory/entities.rb', line 209

def to_h
  {
    tenant_id: @tenant_id,
    feed_id: @feed_id,
    environment_id: environment_id,
    resource_type_id: resource_type_id,
    metric_type_id: metric_type_id,
    resource_ids: resource_ids,
    metric_id: @metric_id
  }
end

#to_resource(resource_id) ⇒ Object

Adds a resource to the path.

Returns:

  • CanonicalPath referring to resource_id using current as its ancestor.



198
199
200
201
202
203
# File 'lib/hawkular/inventory/entities.rb', line 198

def to_resource(resource_id)
  hash = to_h
  hash[:resource_ids] = [] if hash[:resource_ids].nil?
  hash[:resource_ids].push resource_id
  CanonicalPath.new(hash)
end

#to_sObject



221
222
223
224
225
226
227
228
229
230
# File 'lib/hawkular/inventory/entities.rb', line 221

def to_s
  ret = "/t;#{@tenant_id}"
  ret += "/f;#{@feed_id}" unless @feed_id.nil?
  ret += "/e;#{@environment_id}" unless @environment_id.nil?
  ret += "/rt;#{@resource_type_id}" unless @resource_type_id.nil?
  ret += "/mt;#{@metric_type_id}" unless @metric_type_id.nil?
  ret += "/m;#{@metric_id}" unless @metric_id.nil?
  ret += resources_chunk.to_s
  ret
end

#upObject

Move up to the parent path of the resource. resource_ids set to empty array when there is no parent.

Returns:

  • CanonicalPath corresponding to the direct ancestor of the resource represented by this path object.



186
187
188
189
190
191
192
193
194
# File 'lib/hawkular/inventory/entities.rb', line 186

def up
  hash = to_h
  if hash[:resource_ids].nil?
    hash[:resource_ids] = []
  else
    hash[:resource_ids].pop
  end
  CanonicalPath.new(hash)
end