Skip to content

Commit

Permalink
chore: Fix RuboCop Style/DoubleNegation
Browse files Browse the repository at this point in the history
  • Loading branch information
htwroclau committed Mar 3, 2019
1 parent 801f7d5 commit 5c3e62f
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 43 deletions.
17 changes: 3 additions & 14 deletions .rubocop_todo.yml
@@ -1,14 +1,14 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-03-03 20:17:49 +0900 using RuboCop version 0.65.0.
# on 2019-03-04 00:45:24 +0900 using RuboCop version 0.65.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 40
Metrics/AbcSize:
Max: 86
Max: 85

# Offense count: 2
# Configuration parameters: CountComments, ExcludedMethods.
Expand All @@ -19,7 +19,7 @@ Metrics/BlockLength:
# Offense count: 5
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 216
Max: 213

# Offense count: 19
Metrics/CyclomaticComplexity:
Expand Down Expand Up @@ -66,17 +66,6 @@ Style/Documentation:
- 'lib/faraday/response/raise_error.rb'
- 'lib/faraday/utils.rb'

# Offense count: 9
Style/DoubleNegation:
Exclude:
- 'lib/faraday/adapter/em_http.rb'
- 'lib/faraday/adapter/excon.rb'
- 'lib/faraday/adapter/net_http.rb'
- 'lib/faraday/adapter/test.rb'
- 'lib/faraday/connection.rb'
- 'lib/faraday/options/env.rb'
- 'lib/faraday/response.rb'

# Offense count: 2
# Configuration parameters: AllowedVariables.
Style/GlobalVars:
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/adapter.rb
Expand Up @@ -59,7 +59,7 @@ def save_response(env, status, body, headers = nil, reason_phrase = nil)
yield(response_headers) if block_given?
end

env.response.finish(env) unless env.parallel?
env.response.finish(env) unless env.parallel_manager
env.response
end
end
Expand Down
7 changes: 1 addition & 6 deletions lib/faraday/adapter/em_http.rb
Expand Up @@ -101,7 +101,7 @@ def call(env)
end

def perform_request(env)
if parallel?(env)
if env[:parallel_manager]
manager = env[:parallel_manager]
manager.add do
perform_single_request(env)
Expand Down Expand Up @@ -183,11 +183,6 @@ def raise_error(msg)
raise errklass, msg
end

# @return [Boolean]
def parallel?(env)
!!env[:parallel_manager]
end

# This parallel manager is designed to start an EventMachine loop
# and block until all registered requests have been completed.
class Manager
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/adapter/excon.rb
Expand Up @@ -11,7 +11,7 @@ def call(env)

opts = {}
if env[:url].scheme == 'https' && (ssl = env[:ssl])
opts[:ssl_verify_peer] = !!ssl.fetch(:verify, true)
opts[:ssl_verify_peer] = !ssl[:verify]
opts[:ssl_ca_path] = ssl[:ca_path] if ssl[:ca_path]
opts[:ssl_ca_file] = ssl[:ca_file] if ssl[:ca_file]
opts[:client_cert] = ssl[:client_cert] if ssl[:client_cert]
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/adapter/net_http.rb
Expand Up @@ -69,7 +69,7 @@ def call(env)
def create_request(env)
request = Net::HTTPGenericRequest.new \
env[:method].to_s.upcase, # request method
!!env[:body], # is there request body
env[:body].nil?, # is there request body
env[:method] != :head, # is there response body
env[:url].request_uri, # request uri path
env[:request_headers] # request headers
Expand Down
3 changes: 2 additions & 1 deletion lib/faraday/adapter/test.rb
Expand Up @@ -163,7 +163,8 @@ def matches?(request_host, request_uri, request_headers, request_body)

def path_match?(request_path, meta)
if path.is_a? Regexp
!!(meta[:match_data] = path.match(request_path))
meta[:match_data] = path.match(request_path)
meta.key?(:match_data)
else
path == request_path
end
Expand Down
9 changes: 1 addition & 8 deletions lib/faraday/connection.rb
Expand Up @@ -81,7 +81,7 @@ def initialize(url = nil, options = nil)
@params.update(options.params) if options.params
@headers.update(options.headers) if options.headers

@manual_proxy = !!options.proxy
@manual_proxy = options.proxy
@proxy = options.proxy ? ProxyOptions.from(options.proxy) : proxy_from_env(url)
@temp_proxy = @proxy

Expand Down Expand Up @@ -352,13 +352,6 @@ def default_parallel_manager
end
end

# Determine if this Faraday::Connection can make parallel requests.
#
# @return [Boolean]
def in_parallel?
!!@parallel_manager
end

# Sets up the parallel manager to make a set of requests.
#
# @param manager [Object] The parallel manager that this Connection's Adapter uses.
Expand Down
7 changes: 1 addition & 6 deletions lib/faraday/options/env.rb
Expand Up @@ -105,7 +105,7 @@ def []=(key, value)
end

def current_body
!!status ? :response_body : :request_body
status ? :response_body : :request_body
end

def body
Expand Down Expand Up @@ -137,11 +137,6 @@ def parse_body?
!StatusesWithoutBody.include?(status)
end

# @return [Boolean] true if there is a parallel_manager
def parallel?
!!parallel_manager
end

def inspect
attrs = [nil]
members.each do |mem|
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/response.rb
Expand Up @@ -51,7 +51,7 @@ def body
end

def finished?
!!env
env ? true : false
end

def on_complete
Expand Down
4 changes: 2 additions & 2 deletions spec/support/shared_examples/request_method.rb
Expand Up @@ -173,12 +173,12 @@
resp1 = conn.public_send(http_method, '/', payload1)
resp2 = conn.public_send(http_method, '/', payload2)

expect(conn.in_parallel?).to be_truthy
expect(conn.parallel_manager).to be_truthy
expect(resp1.body).to be_nil
expect(resp2.body).to be_nil
end

expect(conn.in_parallel?).to be_falsey
expect(conn.parallel_manager).to be_falsey
expect(resp1&.body).to eq(payload1.to_json)
expect(resp2&.body).to eq(payload2.to_json)
end
Expand Down
4 changes: 2 additions & 2 deletions test/adapters/integration.rb
Expand Up @@ -52,14 +52,14 @@ def test_callback_is_called_in_parallel_with_no_streaming_support
connection.in_parallel do
resp1, streamed1 = streaming_request(connection, :get, 'stream?a=1')
resp2, streamed2 = streaming_request(connection, :get, 'stream?b=2', chunk_size: 16 * 1024)
assert connection.in_parallel?
assert connection.parallel_manager
assert_nil resp1.body
assert_nil resp2.body
assert_equal [], streamed1
assert_equal [], streamed2
end
end
assert !connection.in_parallel?
assert !connection.parallel_manager
assert_match(/Streaming .+ not yet implemented/, err)
opts = { streaming?: false, chunk_size: 16 * 1024 }
check_streaming_response(streamed1, opts.merge(prefix: '{"a"=>"1"}'))
Expand Down

0 comments on commit 5c3e62f

Please sign in to comment.