Class: Gcloud::Logging::Resource
- Inherits:
-
Object
- Object
- Gcloud::Logging::Resource
- Defined in:
- lib/gcloud/logging/resource.rb
Overview
# Resource
A monitored resource is an abstraction used to characterize many kinds of objects in your cloud infrastructure, including Google Cloud SQL databases, Google App Engine apps, Google Compute Engine virtual machine instances, and so forth. Each of those kinds of objects is described by an instance of ResourceDescriptor.
For use with Entry#resource, Project#resource, and Project#write_entries.
Instance Attribute Summary collapse
-
#labels ⇒ Object
A set of labels that can be used to describe instances of this monitored resource type.
-
#type ⇒ Object
The type of resource, as represented by a ResourceDescriptor.
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize ⇒ Resource
constructor
Create an empty Resource object.
-
#to_grpc ⇒ Object
object.
Constructor Details
#initialize ⇒ Resource
Create an empty Resource object.
43 44 45 |
# File 'lib/gcloud/logging/resource.rb', line 43 def initialize @labels = {} end |
Instance Attribute Details
#labels ⇒ Object
A set of labels that can be used to describe instances of this monitored resource type.
54 55 56 |
# File 'lib/gcloud/logging/resource.rb', line 54 def labels @labels end |
#type ⇒ Object
The type of resource, as represented by a Gcloud::Logging::ResourceDescriptor.
49 50 51 |
# File 'lib/gcloud/logging/resource.rb', line 49 def type @type end |
Class Method Details
.from_grpc(grpc) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/gcloud/logging/resource.rb', line 75 def self.from_grpc grpc return new if grpc.nil? new.tap do |r| r.type = grpc.type r.labels = map_to_hash(grpc.labels) end end |
.map_to_hash(map) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/gcloud/logging/resource.rb', line 85 def self.map_to_hash map if map.respond_to? :to_h map.to_h else # Enumerable doesn't have to_h on ruby 2.0... Hash[map.to_a] end end |
Instance Method Details
#empty? ⇒ Boolean
58 59 60 |
# File 'lib/gcloud/logging/resource.rb', line 58 def empty? type.nil? && (labels.nil? || labels.empty?) end |
#to_grpc ⇒ Object
object.
65 66 67 68 69 70 71 |
# File 'lib/gcloud/logging/resource.rb', line 65 def to_grpc return nil if empty? Google::Api::MonitoredResource.new( type: type, labels: Hash[labels.map { |k, v| [String(k), String(v)] }] ) end |