Commit 832fbe5197cca8d9370635304c75db6565da3801
1 parent
6f9fb3c5
Exists in
master
and in
21 other branches
adapt to Faraday sending a hash or an object to `call`
Showing
1 changed file
with
13 additions
and
2 deletions
Show diff stats
lib/searchkick/middleware.rb
... | ... | @@ -3,10 +3,21 @@ require "faraday/middleware" |
3 | 3 | module Searchkick |
4 | 4 | class Middleware < Faraday::Middleware |
5 | 5 | def call(env) |
6 | - if env.method == :get && env.url.path.to_s.end_with?("/_search") | |
7 | - env.request.timeout = Searchkick.search_timeout | |
6 | + is_search = env_value(env, :url).path.to_s.end_with?("/_search") | |
7 | + | |
8 | + if env_value(env, :method) == :get && is_search | |
9 | + r = env_value(env, :request) | |
10 | + if r.is_a?(Hash) | |
11 | + r[:timeout] = Searchkick.search_timeout | |
12 | + else | |
13 | + r.timeout = Searchkick.search_timeout | |
14 | + end | |
8 | 15 | end |
9 | 16 | @app.call(env) |
10 | 17 | end |
18 | + | |
19 | + def env_value(env, key) | |
20 | + env.is_a?(Hash) ? env[key] : env.send(key) | |
21 | + end | |
11 | 22 | end |
12 | 23 | end | ... | ... |