Class: Hawkular::Inventory::BaseEntity

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

Overview

A Basic inventory entity with id, name, path and optional properties

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ BaseEntity

Returns a new instance of BaseEntity



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hawkular/inventory/entities.rb', line 18

def initialize(hash)
  @id = hash['id']
  @path = hash['path']
  @name = hash['name'] || @id
  @properties = hash['properties'] || {}
  @_hash = hash.dup

  return if @path.nil?

  tmp = @path.split('/')
  tmp.each do |pair|
    (key, val) = pair.split(';')
    case key
    when 'f'
      @feed = val
    when 'e'
      @env = val
    end
  end
end

Instance Attribute Details

#envString (readonly)

Returns Name of the environment for this entity

Returns:

  • (String)

    Name of the environment for this entity



14
15
16
# File 'lib/hawkular/inventory/entities.rb', line 14

def env
  @env
end

#feedString (readonly)

Returns Feed this entity belongs to (or nil in case of a feedless entity)

Returns:

  • (String)

    Feed this entity belongs to (or nil in case of a feedless entity)



12
13
14
# File 'lib/hawkular/inventory/entities.rb', line 12

def feed
  @feed
end

#idString (readonly)

Returns Id of the entity

Returns:

  • (String)

    Id of the entity



10
11
12
# File 'lib/hawkular/inventory/entities.rb', line 10

def id
  @id
end

#nameString (readonly)

Returns Name of the entity

Returns:

  • (String)

    Name of the entity



8
9
10
# File 'lib/hawkular/inventory/entities.rb', line 8

def name
  @name
end

#pathString (readonly)

Returns Full path of the entity

Returns:

  • (String)

    Full path of the entity



6
7
8
# File 'lib/hawkular/inventory/entities.rb', line 6

def path
  @path
end

#propertiesString (readonly)

Returns Properties of this entity

Returns:

  • (String)

    Properties of this entity



16
17
18
# File 'lib/hawkular/inventory/entities.rb', line 16

def properties
  @properties
end

Instance Method Details

#==(other) ⇒ Object



39
40
41
# File 'lib/hawkular/inventory/entities.rb', line 39

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

#to_hHash<String,Object>

Returns a hash representation of the resource type

Returns:

  • (Hash<String,Object>)

    hash of the type



45
46
47
# File 'lib/hawkular/inventory/entities.rb', line 45

def to_h
  @_hash.dup
end