diff --git a/.rubocop.yml b/.rubocop.yml index bb13f67..73c2701 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -74,3 +74,13 @@ RaiseArgs: TrailingCommaInLiteral: Enabled: false + +# Ignore length of describe and context blocks +Metrics/BlockLength: + Exclude: + - 'spec/**/*_spec.rb' + +# The RubyGems /api/v1/dependencies endpoint returns serialized ruby objects +# that need to be deserialized within Gems::Client#dependencies. :( +Security/MarshalLoad: + Enabled: false diff --git a/Gemfile b/Gemfile index 55c73ef..8cfe145 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ group :test do gem 'backports' gem 'coveralls' gem 'rspec', '>= 3.1.0' - gem 'rubocop', '>= 0.27' + gem 'rubocop', '>= 0.50' gem 'simplecov', '>= 0.9' gem 'webmock' gem 'yardstick' diff --git a/Rakefile b/Rakefile index d4b154e..d46b786 100644 --- a/Rakefile +++ b/Rakefile @@ -28,4 +28,4 @@ Yardstick::Rake::Verify.new do |verify| verify.threshold = 68.7 end -task :default => [:spec, :rubocop, :verify_measurements] +task :default => %i[spec rubocop verify_measurements] diff --git a/gems.gemspec b/gems.gemspec index d1db86c..a8dde06 100644 --- a/gems.gemspec +++ b/gems.gemspec @@ -1,4 +1,5 @@ # coding: utf-8 + lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'gems/version' @@ -9,11 +10,11 @@ Gem::Specification.new do |spec| spec.authors = ['Erik Michaels-Ober'] spec.description = 'Ruby wrapper for the RubyGems.org API' spec.email = ['sferik@gmail.com'] - spec.files = %w(.yardopts CONTRIBUTING.md LICENSE.md README.md gems.gemspec) + Dir['lib/**/*.rb'] + spec.files = %w[.yardopts CONTRIBUTING.md LICENSE.md README.md gems.gemspec] + Dir['lib/**/*.rb'] spec.homepage = 'https://github.com/rubygems/gems' - spec.licenses = %w(MIT) + spec.licenses = %w[MIT] spec.name = 'gems' - spec.require_paths = %w(lib) + spec.require_paths = %w[lib] spec.required_ruby_version = '>= 2.1.9' spec.summary = spec.description spec.version = Gems::VERSION diff --git a/lib/gems/configuration.rb b/lib/gems/configuration.rb index 7115654..6d562be 100644 --- a/lib/gems/configuration.rb +++ b/lib/gems/configuration.rb @@ -5,12 +5,12 @@ module Gems module Configuration # An array of valid keys in the options hash when configuring a {Gems::Client} - VALID_OPTIONS_KEYS = [ - :host, - :key, - :password, - :user_agent, - :username, + VALID_OPTIONS_KEYS = %i[ + host + key + password + user_agent + username ].freeze # Set the default API endpoint diff --git a/lib/gems/request.rb b/lib/gems/request.rb index 2b06642..859b3f2 100644 --- a/lib/gems/request.rb +++ b/lib/gems/request.rb @@ -23,7 +23,7 @@ def put(path, data = {}, content_type = 'application/x-www-form-urlencoded', req private def request(method, path, data, content_type, request_host = host) # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength, ParameterLists, PerceivedComplexity - path += hash_to_query_string(data) if [:delete, :get].include? method + path += hash_to_query_string(data) if %i[delete get].include? method uri = URI.parse [request_host, path].join request_class = Net::HTTP.const_get method.to_s.capitalize request = request_class.new uri.request_uri @@ -35,7 +35,7 @@ def request(method, path, data, content_type, request_host = host) # rubocop:dis request.content_type = content_type case content_type when 'application/x-www-form-urlencoded' - request.form_data = data if [:post, :put].include? method + request.form_data = data if %i[post put].include? method when 'application/octet-stream' request.body = data request.content_length = data.size @@ -59,9 +59,7 @@ def request(method, path, data, content_type, request_host = host) # rubocop:dis def hash_to_query_string(hash) return '' if hash.empty? - hash.keys.each_with_object('?') do |key, query_string| - query_string << "#{URI.encode(key.to_s)}=#{URI.encode(hash[key])}&" - end.chop! + '?' + URI.encode_www_form(hash) end def body_from_response(response, method, content_type)