Skip to content

Commit

Permalink
Actions with a single parameter don't need a hash
Browse files Browse the repository at this point in the history
  • Loading branch information
SFEley committed Aug 29, 2012
1 parent 8849a20 commit 529ebe9
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 40 deletions.
6 changes: 2 additions & 4 deletions Gemfile
Expand Up @@ -3,13 +3,11 @@ source "http://rubygems.org"
# Specify your gem's dependencies in em-aws.gemspec
gemspec


group :development do
# 2012-02-06:
# Use latest Webmock until the hash_including functionality is released
gem "webmock", git: 'https://github.com/bblimke/webmock.git'
gem "guard-bundler"
gem "guard-rspec"
gem "guard-yard"
gem "growl"
gem "redcarpet"
end

28 changes: 13 additions & 15 deletions Guardfile
@@ -1,20 +1,18 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

group :specs do
guard 'rspec', version: 2, cli: '-c -f doc' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
end
guard 'bundler' do
watch('Gemfile')
end

group :doc do
guard 'yard' do
watch(%r{app/.+\.rb})
watch(%r{lib/.+\.rb})
watch(%r{ext/.+\.c})
watch('README.markdown')
end
end
guard :rspec do # add :turnip => true for Turnip
watch(%r{^spec/.+_spec\.rb$})
watch('spec/spec_helper.rb') { "spec" }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }

# Turnip features and steps
# watch(%r{^spec/acceptance/(.+)\.feature$})
# watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end
2 changes: 1 addition & 1 deletion doc/_index.html
Expand Up @@ -79,7 +79,7 @@ <h2>Namespace Listing A-Z</h2>
</div>

<div id="footer">
Generated on Sun Jul 22 14:55:23 2012 by
Generated on Sun Jul 22 14:59:09 2012 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.2.1 (ruby-1.9.3).
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/index.html
Expand Up @@ -79,7 +79,7 @@ <h2>Namespace Listing A-Z</h2>
</div>

<div id="footer">
Generated on Sun Jul 22 14:55:23 2012 by
Generated on Sun Jul 22 14:59:09 2012 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.2.1 (ruby-1.9.3).
</div>
Expand Down
8 changes: 4 additions & 4 deletions em-aws.gemspec
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.email = ["sfeley@gmail.com"]
s.homepage = ""
s.summary = %q{EventMachine library for Amazon Web Services}
s.description = %q{EM-AWS is a generalized wrapper for the various Amazon Web Services SDKs using EventMachine and a callback-based model for handling responses.}
s.description = %q{EM::AWS is a generalized wrapper for the various Amazon Web Services SDKs using EventMachine and a callback-based model for handling responses.}

s.rubyforge_project = "em-aws"

Expand All @@ -22,7 +22,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "eventmachine"
s.add_runtime_dependency "em-http-request"
s.add_runtime_dependency "nokogiri"
s.add_development_dependency "rspec"
s.add_development_dependency "webmock"

s.add_development_dependency "rspec", '~> 2.11'
s.add_development_dependency "webmock", '~> 1.8.7'
end
17 changes: 15 additions & 2 deletions lib/em-aws/query.rb
Expand Up @@ -81,14 +81,27 @@ module ClassMethods
# @param [Symbol] name The action to be called
# @param [optional, Hash] options
# @option options [Proc] :filter_params A lambda that performs in-place transformations on the parameters
#
# @option options [Symbol] :single_param If an action takes a single value, provide the AWS parameter name for it and a hash will be unnecessary
def action(name, options={})
filter_params = options[:filter_params]
filter_response = options[:filter_response]
single_param = options[:single_param]

define_method(name) do |params={}, &block|
if single_param and !params.is_a?(Hash)
params = {single_param => params}
end
filter_params[params] if filter_params
call name, params, &block

if filter_response
request = call name, params, &filter_response
request.callback &block
request
else
call name, params, &block
end
end

end
end

Expand Down
32 changes: 19 additions & 13 deletions lib/em-aws/query/query_response.rb
Expand Up @@ -5,45 +5,51 @@
module EventMachine
module AWS
module Query

# Shared behaviors for QueryResult and QueryFailure. The class this is mixed into MUST have a
# 'ResponseParser' class within its namespace.
module QueryResponse
include Inflections

attr_reader :result, :metadata

def initialize(http_response)
super
@result, @metadata = {}, {}
parse @body unless @body.empty?
end

# Returns the specified key from the inner 'SomeActionResults' data.
def [](val)
@result[val] || @result[symbolize(val)]
def [](key)
@result[key] || @result[symbolize(key)]
end

# Sets the specified key. Primarily intended for use in
# response filtering callbacks.
def []=(key, value)
@result[key] = value
end

def request_id
metadata[:request_id]
end

def method_missing(name, *args, &block)
if @result.has_key? name # Make sure nil values are returned correctly
@result[name]
@result[name]
else
super
end
end

protected

def parse(xml)
parser = Nokogiri::XML::SAX::Parser.new ResponseParser.new(@result, @metadata)
parser.parse xml
end
end

end
end
end
end

0 comments on commit 529ebe9

Please sign in to comment.