Class: Hawkular::Inventory::Resource
- Inherits:
-
Object
- Object
- Hawkular::Inventory::Resource
- Defined in:
- lib/hawkular/inventory/entities.rb
Instance Attribute Summary collapse
-
#config ⇒ Hash<String,String>
readonly
Config map of this resource.
-
#feed ⇒ String
readonly
Feed this entity belongs to.
-
#id ⇒ String
readonly
Id of the entity.
-
#name ⇒ String
readonly
Name of the entity.
-
#parent_id ⇒ String
readonly
Parent ID of this entity (nil if it’s a root resource).
-
#properties ⇒ Hash<String,String>
readonly
Properties of this resource.
-
#type ⇒ ResourceType
readonly
Type of this resource.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #children(recursive = false) ⇒ Object
- #children_by_type(type, recursive = false) ⇒ Object
-
#initialize(hash) ⇒ Resource
constructor
A new instance of Resource.
- #metrics(recursive = false) ⇒ Object
- #metrics_by_family(family) ⇒ Object
-
#to_h ⇒ Hash<String,Object>
Returns a hash representation of the resource.
Constructor Details
#initialize(hash) ⇒ Resource
Returns a new instance of Resource.
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/hawkular/inventory/entities.rb', line 90 def initialize(hash) @id = hash['id'] @name = hash['name'] @feed = hash['feedId'] @type = ResourceType.new(hash['type']) @parent_id = hash['parentId'] @properties = hash['properties'] || {} @config = hash['config'] || {} @metrics = (hash['metrics'] || []).map { |m| Metric.new(m) } @children = hash['children'].map { |r| Resource.new(r) } if hash.key? 'children' @_hash = hash.dup end |
Instance Attribute Details
#config ⇒ Hash<String,String> (readonly)
Returns Config map of this resource.
88 89 90 |
# File 'lib/hawkular/inventory/entities.rb', line 88 def config @config end |
#feed ⇒ String (readonly)
Returns Feed this entity belongs to.
80 81 82 |
# File 'lib/hawkular/inventory/entities.rb', line 80 def feed @feed end |
#id ⇒ String (readonly)
Returns Id of the entity.
76 77 78 |
# File 'lib/hawkular/inventory/entities.rb', line 76 def id @id end |
#name ⇒ String (readonly)
Returns Name of the entity.
78 79 80 |
# File 'lib/hawkular/inventory/entities.rb', line 78 def name @name end |
#parent_id ⇒ String (readonly)
Returns Parent ID of this entity (nil if it’s a root resource).
84 85 86 |
# File 'lib/hawkular/inventory/entities.rb', line 84 def parent_id @parent_id end |
#properties ⇒ Hash<String,String> (readonly)
Returns Properties of this resource.
86 87 88 |
# File 'lib/hawkular/inventory/entities.rb', line 86 def properties @properties end |
#type ⇒ ResourceType (readonly)
Returns Type of this resource.
82 83 84 |
# File 'lib/hawkular/inventory/entities.rb', line 82 def type @type end |
Instance Method Details
#==(other) ⇒ Object
124 125 126 |
# File 'lib/hawkular/inventory/entities.rb', line 124 def ==(other) equal?(other) || other.class == self.class && other.id == @id end |
#children(recursive = false) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/hawkular/inventory/entities.rb', line 103 def children(recursive = false) return @children unless recursive == true fail Hawkular::ArgumentError 'Resource tree not loaded, load it by calling resource_tree' if @children.nil? @children.flat_map do |child| [child, *child.children(recursive)] end end |
#children_by_type(type, recursive = false) ⇒ Object
111 112 113 |
# File 'lib/hawkular/inventory/entities.rb', line 111 def children_by_type(type, recursive = false) children(recursive).select { |c| c.type.id == type } end |
#metrics(recursive = false) ⇒ Object
115 116 117 118 |
# File 'lib/hawkular/inventory/entities.rb', line 115 def metrics(recursive = false) return @metrics unless recursive == true children(recursive).collect(&:metrics).flat_map(&:itself).concat(@metrics) end |
#metrics_by_family(family) ⇒ Object
120 121 122 |
# File 'lib/hawkular/inventory/entities.rb', line 120 def metrics_by_family(family) @metrics.select { |m| m.family == family } end |
#to_h ⇒ Hash<String,Object>
Returns a hash representation of the resource
130 131 132 |
# File 'lib/hawkular/inventory/entities.rb', line 130 def to_h @_hash.dup end |