class AWS::EC2::Resource

@private

def __resource_id__

def __resource_id__
  send(resource_id_method)
end

def describe_attribute_call(attribute)

def describe_attribute_call(attribute)
  name = describe_attribute_call_name
  attr_opt_name = Core::Inflection.class_name(attribute.get_as.to_s)
  attr_opt_name = attr_opt_name[0,1].downcase + attr_opt_name[1..-1]
  client.send(name, Hash[[[response_id_method.to_sym,
                           __resource_id__],
                          [:attribute, attr_opt_name]]])
end

def describe_call

def describe_call
  options = { :"#{response_id_method}s" => [__resource_id__] }
  client.send(describe_call_name, options)
end

def describe_call_attribute(name, opts = {}, &blk)

def describe_call_attribute(name, opts = {}, &blk)
  attribute(name, opts, &blk)
end

def find_in_response response

def find_in_response response
  self.class.attribute_providers.each do |provider|
    if provider.request_types.include?(response.request_type)
      return send(provider.finder_method, response)
    end
  end
end

def get_resource attribute = nil

def get_resource attribute = nil
  describe_call
end

def resource_id_method

def resource_id_method
  @resource_id_method ||=
    case
    when respond_to?(:id) && method(:id).owner != Kernel
      # id isn't defined on Object in some Ruby versions, in
      # others it is an alias for object_id; if the method is
      # not owned by Kernel we can assume that it has been
      # overridden in a subclass
      :id
    when respond_to?(:name)
      :name
    else
      raise NotImplementedError
    end
end

def resource_identifiers

def resource_identifiers
  [[resource_id_method, send(resource_id_method)]]
end

def response_id_method

def response_id_method
  # e.g. instance_id
  inflected_name + "_" + resource_id_method.to_s
end

def retrieve_attribute attribute_or_attribute_name, &block

def retrieve_attribute attribute_or_attribute_name, &block
  if attribute_or_attribute_name.is_a?(Symbol)
    attribute = self.class.attributes[attribute_or_attribute_name]
  else
    attribute = attribute_or_attribute_name
  end
  super(attribute, &block)
end

def update_resource attribute, value

def update_resource attribute, value
  options = {}
  if value.is_a?(Array)
    options[attribute.set_as] = value
  else
    options[attribute.set_as] = { :value => value }
  end
  options[:"#{inflected_name}_id"] = __resource_id__
  method_name = "modify_#{inflected_name}_attribute"
  client.send(method_name, options)
end