Class: Google::Cloud::Env::ComputeMetadata::Overrides
- Inherits:
-
Object
- Object
- Google::Cloud::Env::ComputeMetadata::Overrides
- Defined in:
- lib/google/cloud/env/compute_metadata.rb
Overview
A set of overrides for metadata access. This is used in #overrides= and #with_overrides. Generally, you should create and populate an overrides object, then set it using one of those methods.
An empty overrides object that contains no data is interpreted as a metadata server that does not respond and raises MetadataServerNotResponding. Otherwise, the overrides specifies what responses are returned for specified queries, and any query not explicitly set will result in a 404.
Instance Method Summary collapse
-
#add(path, string, query: nil, headers: nil) ⇒ self
Add an override to the object, providing just a body string.
-
#add_ping ⇒ self
Add an override for the ping request.
-
#add_response(path, response, query: nil) ⇒ self
Add an override to the object, providing a full response.
-
#clear ⇒ self
Clear all data from these overrides.
-
#empty? ⇒ true, false
Returns true if there is at least one override present.
-
#initialize ⇒ Overrides
constructor
Create an empty overrides object.
-
#lookup(path, query: nil) ⇒ String?
Look up a response from the override data.
Constructor Details
#initialize ⇒ Overrides
Create an empty overrides object.
160 161 162 |
# File 'lib/google/cloud/env/compute_metadata.rb', line 160 def initialize clear end |
Instance Method Details
#add(path, string, query: nil, headers: nil) ⇒ self
Add an override to the object, providing just a body string.
189 190 191 192 193 |
# File 'lib/google/cloud/env/compute_metadata.rb', line 189 def add path, string, query: nil, headers: nil headers = (headers || {}).merge FLAVOR_HEADER response = Response.new 200, string, headers add_response path, response, query: query end |
#add_ping ⇒ self
Add an override for the ping request.
200 201 202 |
# File 'lib/google/cloud/env/compute_metadata.rb', line 200 def add_ping add nil, "computeMetadata/\n" end |
#add_response(path, response, query: nil) ⇒ self
Add an override to the object, providing a full response.
174 175 176 177 |
# File 'lib/google/cloud/env/compute_metadata.rb', line 174 def add_response path, response, query: nil @data[[path, query || {}]] = response self end |
#clear ⇒ self
Clear all data from these overrides
209 210 211 212 |
# File 'lib/google/cloud/env/compute_metadata.rb', line 209 def clear @data = {} self end |
#empty? ⇒ true, false
Returns true if there is at least one override present
233 234 235 |
# File 'lib/google/cloud/env/compute_metadata.rb', line 233 def empty? @data.empty? end |
#lookup(path, query: nil) ⇒ String?
Look up a response from the override data.
224 225 226 |
# File 'lib/google/cloud/env/compute_metadata.rb', line 224 def lookup path, query: nil @data[[path, query || {}]] end |