Fixed incompatibilities with Ruby 1.8.6

git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@71 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef
This commit is contained in:
Bob Aman 2010-10-13 21:16:07 +00:00
parent 61fc497f2c
commit 5572a73fdf
4 changed files with 19 additions and 13 deletions

View File

@ -442,7 +442,9 @@ module Google
# #
# @return [Hash] The parameter descriptions. # @return [Hash] The parameter descriptions.
def parameter_descriptions def parameter_descriptions
@parameter_descriptions ||= Hash[self.description['parameters'] || {}] @parameter_descriptions ||= (
self.description['parameters'] || {}
).inject({}) { |h,(k,v)| h[k]=v; h }
end end
## ##
@ -450,7 +452,9 @@ module Google
# #
# @return [Array] The parameters. # @return [Array] The parameters.
def parameters def parameters
@parameters ||= Hash[self.description['parameters'] || {}].keys @parameters ||= ((
self.description['parameters'] || {}
).inject({}) { |h,(k,v)| h[k]=v; h }).keys
end end
## ##
@ -463,9 +467,9 @@ module Google
# # A list of all required parameters. # # A list of all required parameters.
# method.required_parameters # method.required_parameters
def required_parameters def required_parameters
@required_parameters ||= Hash[self.parameter_descriptions.select do |k, v| @required_parameters ||= ((self.parameter_descriptions.select do |k, v|
v['required'] v['required']
end].keys end).inject({}) { |h,(k,v)| h[k]=v; h }).keys
end end
## ##
@ -478,9 +482,9 @@ module Google
# # A list of all optional parameters. # # A list of all optional parameters.
# method.optional_parameters # method.optional_parameters
def optional_parameters def optional_parameters
@optional_parameters ||= Hash[self.parameter_descriptions.reject do |k, v| @optional_parameters ||= ((self.parameter_descriptions.reject do |k, v|
v['required'] v['required']
end].keys end).inject({}) { |h,(k,v)| h[k]=v; h }).keys
end end
## ##
@ -493,9 +497,9 @@ module Google
# @return [NilClass] <code>nil</code> if validation passes. # @return [NilClass] <code>nil</code> if validation passes.
def validate_parameters(parameters={}) def validate_parameters(parameters={})
parameters = self.normalize_parameters(parameters) parameters = self.normalize_parameters(parameters)
required_variables = Hash[self.parameter_descriptions.select do |k, v| required_variables = ((self.parameter_descriptions.select do |k, v|
v['required'] v['required']
end].keys end).inject({}) { |h,(k,v)| h[k]=v; h }).keys
missing_variables = required_variables - parameters.keys missing_variables = required_variables - parameters.keys
if missing_variables.size > 0 if missing_variables.size > 0
raise ArgumentError, raise ArgumentError,

View File

@ -173,7 +173,7 @@ describe Google::APIClient, 'configured for the prediction API' do
method.should == 'POST' method.should == 'POST'
uri.should == uri.should ==
'https://www.googleapis.com/prediction/v1/training?query=12345' 'https://www.googleapis.com/prediction/v1/training?query=12345'
Hash[headers].should == {} (headers.inject({}) { |h,(k,v)| h[k]=v; h }).should == {}
body.should respond_to(:each) body.should respond_to(:each)
end end
@ -207,7 +207,7 @@ describe Google::APIClient, 'configured for the prediction API' do
{'query' => '12345'} {'query' => '12345'}
) )
method, uri, headers, body = request method, uri, headers, body = request
headers = Hash[headers] headers = headers.inject({}) { |h,(k,v)| h[k]=v; h }
headers.keys.should include('Authorization') headers.keys.should include('Authorization')
headers['Authorization'].should =~ /^OAuth/ headers['Authorization'].should =~ /^OAuth/
end end

View File

@ -19,14 +19,14 @@ namespace :gem do
s.extra_rdoc_files = %w( README ) s.extra_rdoc_files = %w( README )
s.rdoc_options.concat ['--main', 'README'] s.rdoc_options.concat ['--main', 'README']
s.add_runtime_dependency('signet', '>= 0.1.1') s.add_runtime_dependency('signet', '>= 0.1.3')
s.add_runtime_dependency('addressable', '>= 2.2.2') s.add_runtime_dependency('addressable', '>= 2.2.2')
s.add_runtime_dependency('httpadapter', '>= 0.2.0') s.add_runtime_dependency('httpadapter', '>= 0.2.0')
s.add_runtime_dependency('json', '>= 1.1.9') s.add_runtime_dependency('json', '>= 1.1.9')
s.add_runtime_dependency('extlib', '>= 0.9.15') s.add_runtime_dependency('extlib', '>= 0.9.15')
s.add_development_dependency('rake', '>= 0.7.3') s.add_development_dependency('rake', '>= 0.7.3')
s.add_development_dependency('rspec', '~> 1.3.0') s.add_development_dependency('rspec', '~> 1.2.9')
s.add_development_dependency('launchy', '>= 0.3.2') s.add_development_dependency('launchy', '>= 0.3.2')
s.add_development_dependency('diff-lcs', '>= 1.1.2') s.add_development_dependency('diff-lcs', '>= 1.1.2')

View File

@ -7,7 +7,9 @@ namespace :spec do
if RCOV_ENABLED if RCOV_ENABLED
if `which rcov`.strip == "" if `which rcov`.strip == ""
STDERR.puts "Please install rcov:" STDERR.puts "Please install rcov:"
STDERR.puts "sudo gem install relevance-rcov" STDERR.puts(
"sudo gem install relevance-rcov --source http://gems.github.com/"
)
exit(1) exit(1)
end end
t.rcov = true t.rcov = true