@private
# File lib/aws/core/resource.rb, line 341 def initialize klass, request_types @klass = klass @id = klass.attribute_providers.length @request_types = request_types @provides = {} end
# File lib/aws/core/resource.rb, line 380 def attributes_from_response resource, response if response_object = resource.send(finder_method, response) attributes_from_response_object(response_object) else nil end end
# File lib/aws/core/resource.rb, line 388 def attributes_from_response_object resp_obj @provides.inject({}) do |attributes,(attr_name,options)| attr = @klass.attributes[attr_name] methods = [options[:from] || attr.from].flatten v = resp_obj methods.each do |method| v = v.key?(method) ? v[method] : v[method.to_s] break if v.nil? end v = v[:value] if v and options[:value_wrapped] v = attr.translate_output_value(v) attributes.merge(attr_name => v) end end
# File lib/aws/core/resource.rb, line 350 def find &block @klass.send(:define_method, finder_method, &block) end
# File lib/aws/core/resource.rb, line 354 def finder_method "_find_in_#{request_types.join('_or_')}_response_#{@id}" end
Indicates that all of the the named attributes can be retrieved from an appropriate response object.
@overload provides(*attr_names, options = {})
@param [Symbol] attr_names A list of attributes provided @param [Hash] options @option options [Boolean] :value_wrapped (false) If true, then the value returned by the response object will also receive the message :value before it is translated and returned. @option options [Symbol] :from Defaults to the method named by the attribute. This is useful when you have two providers for the same attribute but their response object name them differently.
# File lib/aws/core/resource.rb, line 371 def provides *attr_names options = 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] = options end end