@private
# File lib/aws/core/resource.rb, line 313 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 351 def attributes_from_response resource, response if response_object = resource.send(finder_method, response) attributes_from_response_object(response_object) else {} end end
# File lib/aws/core/resource.rb, line 359 def attributes_from_response_object resp_obj attributes = {} @provides.each do |attr_name, options| attr = @klass.attributes[attr_name] method = options[:get_as] || attr.get_as v = case when resp_obj.respond_to?(:key?) && resp_obj.key?(method.to_s) resp_obj[method.to_s] when resp_obj.respond_to?(method) resp_obj.send(method) else nil end v = v.value if v and options[:value_wrapped] v = attr.translate_output_value(v) attributes[attr_name] = v end attributes end
# File lib/aws/core/resource.rb, line 322 def find &block @klass.send(:define_method, finder_method, &block) end
# File lib/aws/core/resource.rb, line 326 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.
@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] :get_as 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 342 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