Class: AWS::Core::Resource::AttributeProvider
- Inherits:
-
Object
- Object
- AWS::Core::Resource::AttributeProvider
- Defined in:
- lib/aws/core/resource.rb
Instance Attribute Summary collapse
-
#request_types ⇒ Object
readonly
Returns the value of attribute request_types.
Instance Method Summary collapse
- #attributes_from_response(resource, response) ⇒ Object
- #attributes_from_response_object(resp_obj) ⇒ Object
- #find(&block) ⇒ Object
- #finder_method ⇒ Object
-
#initialize(klass, request_types) ⇒ AttributeProvider
constructor
A new instance of AttributeProvider.
-
#provides(*attr_names, options = {}) ⇒ Object
Indicates that all of the the named attributes can be retrieved from an appropriate response object.
Constructor Details
#initialize(klass, request_types) ⇒ AttributeProvider
Returns a new instance of AttributeProvider.
340 341 342 343 344 345 |
# File 'lib/aws/core/resource.rb', line 340 def initialize klass, request_types @klass = klass @id = klass.attribute_providers.length @request_types = request_types @provides = {} end |
Instance Attribute Details
#request_types ⇒ Object (readonly)
Returns the value of attribute request_types.
347 348 349 |
# File 'lib/aws/core/resource.rb', line 347 def request_types @request_types end |
Instance Method Details
#attributes_from_response(resource, response) ⇒ Object
379 380 381 382 383 384 385 |
# File 'lib/aws/core/resource.rb', line 379 def attributes_from_response resource, response if response_object = resource.send(finder_method, response) attributes_from_response_object(response_object) else nil end end |
#attributes_from_response_object(resp_obj) ⇒ Object
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/aws/core/resource.rb', line 387 def attributes_from_response_object resp_obj @provides.inject({}) do |attributes,(attr_name,)| attr = @klass.attributes[attr_name] method = [:get_as] || attr.get_as v = resp_obj.key?(method) ? resp_obj[method] : resp_obj[method.to_s] v = v[:value] if v and [:value_wrapped] v = attr.translate_output_value(v) attributes.merge(attr_name => v) end end |
#find(&block) ⇒ Object
349 350 351 |
# File 'lib/aws/core/resource.rb', line 349 def find &block @klass.send(:define_method, finder_method, &block) end |
#finder_method ⇒ Object
353 354 355 |
# File 'lib/aws/core/resource.rb', line 353 def finder_method "_find_in_#{request_types.join('_or_')}_response_#{@id}" end |
#provides(*attr_names, options = {}) ⇒ Object
Indicates that all of the the named attributes can be retrieved from an appropriate response object.
370 371 372 373 374 375 376 377 |
# File 'lib/aws/core/resource.rb', line 370 def provides *attr_names = attr_names.last.is_a?(Hash) ? attr_names.pop : {} attr_names.each do |attr_name| attr = @klass.attributes[attr_name] attr.request_types.push(*request_types) @provides[attr_name] = end end |