class AWS::Core::Resource::AttributeProvider
@api private
def attributes_from_response resource, response
def attributes_from_response resource, response if response_object = resource.send(finder_method, response) attributes_from_response_object(response_object) else nil end end
def attributes_from_response_object resp_obj
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
def find &block
def find &block @klass.send(:define_method, finder_method, &block) end
def finder_method
def finder_method "_find_in_#{request_types.join('_or_')}_response_#{@id}" end
def initialize klass, request_types
def initialize klass, request_types @klass = klass @id = klass.attribute_providers.length @request_types = request_types @provides = {} end
def provides *attr_names
(**options)
-
:from
(Symbol
) -- Defaults to the method named -
:value_wrapped
(Boolean
) -- If true, then
Parameters:
-
options
(Hash
) -- -
attr_names
(Symbol
) -- A list of attributes provided
Overloads:
-
provides(*attr_names, options = {})
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