mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-04 00:02:03 -04:00
chore: Fix RuboCop Style/BlockDelimiters (#906)
This commit is contained in:
parent
c1febd329f
commit
f46a17573d
@ -39,26 +39,6 @@ Metrics/ModuleLength:
|
||||
Metrics/PerceivedComplexity:
|
||||
Max: 21
|
||||
|
||||
# Offense count: 13
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods.
|
||||
# SupportedStyles: line_count_based, semantic, braces_for_chaining
|
||||
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
|
||||
# FunctionalMethods: let, let!, subject, watch
|
||||
# IgnoredMethods: lambda, proc, it
|
||||
Style/BlockDelimiters:
|
||||
Exclude:
|
||||
- 'lib/faraday/adapter/em_http.rb'
|
||||
- 'lib/faraday/adapter/em_synchrony.rb'
|
||||
- 'lib/faraday/adapter/em_synchrony/parallel_manager.rb'
|
||||
- 'lib/faraday/adapter/test.rb'
|
||||
- 'lib/faraday/connection.rb'
|
||||
- 'lib/faraday/rack_builder.rb'
|
||||
- 'lib/faraday/utils.rb'
|
||||
- 'spec/faraday/request/url_encoded_spec.rb'
|
||||
- 'spec/faraday/utils_spec.rb'
|
||||
- 'spec/support/fake_safe_buffer.rb'
|
||||
|
||||
# Offense count: 8
|
||||
Style/CaseEquality:
|
||||
Exclude:
|
||||
|
@ -103,29 +103,29 @@ module Faraday
|
||||
def perform_request(env)
|
||||
if parallel?(env)
|
||||
manager = env[:parallel_manager]
|
||||
manager.add {
|
||||
manager.add do
|
||||
perform_single_request(env)
|
||||
.callback { env[:response].finish(env) }
|
||||
}
|
||||
end
|
||||
elsif EventMachine.reactor_running?
|
||||
# EM is running: instruct upstream that this is an async request
|
||||
env[:parallel_manager] = true
|
||||
perform_single_request(env)
|
||||
.callback { env[:response].finish(env) }
|
||||
.errback {
|
||||
.errback do
|
||||
# TODO: no way to communicate the error in async mode
|
||||
raise NotImplementedError
|
||||
}
|
||||
end
|
||||
else
|
||||
error = nil
|
||||
# start EM, block until request is completed
|
||||
EventMachine.run do
|
||||
perform_single_request(env)
|
||||
.callback { EventMachine.stop }
|
||||
.errback { |client|
|
||||
.errback do |client|
|
||||
error = error_message(client)
|
||||
EventMachine.stop
|
||||
}
|
||||
end
|
||||
end
|
||||
raise_error(error) if error
|
||||
end
|
||||
@ -146,7 +146,7 @@ module Faraday
|
||||
# TODO: reuse the connection to support pipelining
|
||||
def perform_single_request(env)
|
||||
req = create_request(env)
|
||||
req.setup_request(env[:method], request_config(env)).callback { |client|
|
||||
req.setup_request(env[:method], request_config(env)).callback do |client|
|
||||
if env[:request].stream_response?
|
||||
warn "Streaming downloads for #{self.class.name} are not yet implemented."
|
||||
env[:request].on_data.call(client.response, client.response.bytesize)
|
||||
@ -158,7 +158,7 @@ module Faraday
|
||||
resp_headers[name.to_sym] = value
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def create_request(env)
|
||||
|
@ -52,10 +52,10 @@ module Faraday
|
||||
|
||||
if !EM.reactor_running?
|
||||
EM.run do
|
||||
Fiber.new {
|
||||
Fiber.new do
|
||||
client = block.call
|
||||
EM.stop
|
||||
}.resume
|
||||
end.resume
|
||||
end
|
||||
else
|
||||
client = block.call
|
||||
|
@ -24,12 +24,12 @@ module Faraday
|
||||
def run
|
||||
result = nil
|
||||
if !EM.reactor_running?
|
||||
EM.run {
|
||||
EM.run do
|
||||
Fiber.new do
|
||||
result = perform
|
||||
EM.stop
|
||||
end.resume
|
||||
}
|
||||
end
|
||||
else
|
||||
result = perform
|
||||
end
|
||||
|
@ -103,9 +103,11 @@ module Faraday
|
||||
@stack.each do |method, stubs|
|
||||
next if stubs.empty?
|
||||
|
||||
failed_stubs.concat(stubs.map { |stub|
|
||||
"Expected #{method} #{stub}."
|
||||
})
|
||||
failed_stubs.concat(
|
||||
stubs.map do |stub|
|
||||
"Expected #{method} #{stub}."
|
||||
end
|
||||
)
|
||||
end
|
||||
raise failed_stubs.join(' ') unless failed_stubs.empty?
|
||||
end
|
||||
|
@ -366,11 +366,11 @@ module Faraday
|
||||
# @yield a block to execute multiple requests.
|
||||
# @return [void]
|
||||
def in_parallel(manager = nil)
|
||||
@parallel_manager = manager || default_parallel_manager {
|
||||
@parallel_manager = manager || default_parallel_manager do
|
||||
warn 'Warning: `in_parallel` called but no parallel-capable adapter on Faraday stack'
|
||||
warn caller[2, 10].join("\n")
|
||||
nil
|
||||
}
|
||||
end
|
||||
yield
|
||||
@parallel_manager && @parallel_manager.run
|
||||
ensure
|
||||
|
@ -21,10 +21,10 @@ module Faraday
|
||||
# ActionDispatch::MiddlewareStack::Middleware
|
||||
class Handler
|
||||
@@constants_mutex = Mutex.new
|
||||
@@constants = Hash.new { |h, k|
|
||||
@@constants = Hash.new do |h, k|
|
||||
value = k.respond_to?(:constantize) ? k.constantize : Object.const_get(k)
|
||||
@@constants_mutex.synchronize { h[k] = value }
|
||||
}
|
||||
end
|
||||
|
||||
attr_reader :name
|
||||
|
||||
|
@ -18,9 +18,9 @@ module Faraday
|
||||
ESCAPE_RE = /[^a-zA-Z0-9 .~_-]/
|
||||
|
||||
def escape(str)
|
||||
str.to_s.gsub(ESCAPE_RE) { |match|
|
||||
str.to_s.gsub(ESCAPE_RE) do |match|
|
||||
'%' + match.unpack('H2' * match.bytesize).join('%').upcase
|
||||
}.tr(' ', '+')
|
||||
end.tr(' ', '+')
|
||||
end
|
||||
|
||||
def unescape(str) CGI.unescape str.to_s end
|
||||
|
@ -56,10 +56,10 @@ RSpec.describe Faraday::Request::UrlEncoded do
|
||||
end
|
||||
|
||||
it 'works with unicode' do
|
||||
err = capture_warnings {
|
||||
err = capture_warnings do
|
||||
response = conn.post('/echo', str: 'eé cç aã aâ')
|
||||
expect(response.body).to eq('str=e%C3%A9+c%C3%A7+a%C3%A3+a%C3%A2')
|
||||
}
|
||||
end
|
||||
expect(err.empty?).to be_truthy
|
||||
end
|
||||
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
RSpec.describe Faraday::Utils do
|
||||
describe 'headers parsing' do
|
||||
let(:multi_response_headers) {
|
||||
let(:multi_response_headers) do
|
||||
"HTTP/1.x 500 OK\r\nContent-Type: text/html; charset=UTF-8\r\n" \
|
||||
"HTTP/1.x 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n"
|
||||
}
|
||||
end
|
||||
|
||||
it 'parse headers for aggregated responses' do
|
||||
headers = Faraday::Utils::Headers.new
|
||||
|
@ -5,9 +5,9 @@ FakeSafeBuffer = Struct.new(:string) do
|
||||
def to_s; self end
|
||||
|
||||
def gsub(regex)
|
||||
string.gsub(regex) {
|
||||
string.gsub(regex) do
|
||||
match, = $&, '' =~ /a/
|
||||
yield(match)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user