Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Commit

Permalink
Removed use of #method_missing from the base client.
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorrowe committed Oct 6, 2014
1 parent 401aeab commit 95f5e0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 32 deletions.
42 changes: 12 additions & 30 deletions aws-sdk-core/lib/seahorse/client/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,38 +56,8 @@ def operation_names
self.class.api.operation_names
end

# @api private
def respond_to?(method_name, *args)
if request_method?(method_name)
true
else
super
end
end

# @api private
def method_missing(method_name, *args, &block)
if request_method?(method_name)
make_request(method_name, *args, &block)
else
super
end
end

private

# @return [Boolean] Returns `true` if the method name is an API operation.t
def request_method?(method_name)
operation_names.include?(method_name.to_sym)
end

# Builds and sends a request.
def make_request(name, *args, &block)
params = args[0] || {}
options = args[1] || {}
build_request(name, params).send_request(options, &block)
end

# Constructs a {Configuration} object and gives each plugin the
# opportunity to register options with default values.
def build_config(plugins, options)
Expand Down Expand Up @@ -214,6 +184,8 @@ def set_api(api)
else
@api = api
end
define_operation_methods
@api
end

# @option options [Model::Api, Hash] :api ({})
Expand All @@ -232,6 +204,16 @@ def define(options = {})

private

def define_operation_methods
@api.operation_names.each do |method_name|
define_method(method_name) do |*args, &block|
params = args[0] || {}
options = args[1] || {}
build_request(method_name, params).send_request(options, &block)
end
end
end

def build_plugins
plugins.map { |plugin| plugin.is_a?(Class) ? plugin.new : plugin }
end
Expand Down
4 changes: 2 additions & 2 deletions aws-sdk-core/spec/seahorse/client/plugins/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Plugins
let(:client_class) do
client_class = Client::Base.define api: {
'operations' => {
'Operation' => { 'name' => 'Operation' },
'OperationName' => { 'name' => 'OperationName' },
}
}
client_class.clear_plugins
Expand All @@ -24,7 +24,7 @@ module Plugins

it 'populates the http request endpoint' do
client = client_class.new(endpoint:'https://foo.com')
resp = client.build_request('operation').send_request
resp = client.build_request('operation_name').send_request
expect(resp.context.http_request.endpoint).to eq(URI.parse('https://foo.com/'))
end

Expand Down

0 comments on commit 95f5e0e

Please sign in to comment.