class Hawkular::Inventory::Resource

Attributes

config[R]

@return [Hash<String,String>] Config map of this resource

feed[R]

@return [String] Feed this entity belongs to

id[R]

@return [String] Id of the entity

name[R]

@return [String] Name of the entity

parent_id[R]

@return [String] Parent ID of this entity (nil if it's a root resource)

properties[R]

@return [Hash<String,String>] Properties of this resource

type[R]

@return [ResourceType] Type of this resource

Public Class Methods

new(hash) click to toggle source
    # File lib/hawkular/inventory/entities.rb
 90 def initialize(hash)
 91   @id = hash['id']
 92   @name = hash['name']
 93   @feed = hash['feedId']
 94   @type = ResourceType.new(hash['type'])
 95   @parent_id = hash['parentId']
 96   @properties = hash['properties'] || {}
 97   @config = hash['config'] || {}
 98   @metrics = (hash['metrics'] || []).map { |m| Metric.new(m) }
 99   @children = hash['children'].map { |r| Resource.new(r) } if hash.key? 'children'
100   @_hash = hash.dup
101 end

Public Instance Methods

==(other) click to toggle source
    # File lib/hawkular/inventory/entities.rb
124 def ==(other)
125   equal?(other) || other.class == self.class && other.id == @id
126 end
children(recursive = false) click to toggle source
    # File lib/hawkular/inventory/entities.rb
103 def children(recursive = false)
104   return @children unless recursive == true
105   fail Hawkular::ArgumentError 'Resource tree not loaded, load it by calling resource_tree' if @children.nil?
106   @children.flat_map do |child|
107     [child, *child.children(recursive)]
108   end
109 end
children_by_type(type, recursive = false) click to toggle source
    # File lib/hawkular/inventory/entities.rb
111 def children_by_type(type, recursive = false)
112   children(recursive).select { |c| c.type.id == type }
113 end
metrics(recursive = false) click to toggle source
    # File lib/hawkular/inventory/entities.rb
115 def metrics(recursive = false)
116   return @metrics unless recursive == true
117   children(recursive).collect(&:metrics).flat_map(&:itself).concat(@metrics)
118 end
metrics_by_family(family) click to toggle source
    # File lib/hawkular/inventory/entities.rb
120 def metrics_by_family(family)
121   @metrics.select { |m| m.family == family }
122 end
to_h() click to toggle source

Returns a hash representation of the resource @return [Hash<String,Object>] hash of the resource

    # File lib/hawkular/inventory/entities.rb
130 def to_h
131   @_hash.dup
132 end