-
Notifications
You must be signed in to change notification settings - Fork 976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid 'last arg as keyword param' warning when building user middleware on Ruby 2.7 #1153
Avoid 'last arg as keyword param' warning when building user middleware on Ruby 2.7 #1153
Commits on May 8, 2020
-
Avoid 'last arg as keyword param' warning when building user middleware
This change marks the methods which construct user middleware, so they are called with the 2.6 keyword argument behaviour in 2.7 (and avoid printing a warning about it). Some users add their own middleware & write their own constructors with named parameters, and use keyword arguments when adding their middleware to the builder: ``` class MyMiddleware < Faraday::Middleware def initialize(app, my_argument:) @app = app @my_argument = my_argument end [...] connection = Faraday.new() do |configuration| configuration.use MyMiddleware, my_argument: 'hello' end ``` This works great in 2.6 & 2.7, but 2.7 prints a deprecation warning: ``` /Users/danielholz/.gem/ruby/2.7.0/gems/faraday-1.0.1/lib/faraday/dependency_loader.rb:21: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call /Users/danielholz/code/some_project/lib/some_project/faraday_middleware.rb:2: warning: The called method `initialize' is defined here ``` The warning is a bit frustrating, since the calling code is not in the user's code, so they cannot add `**` to the call. The best option for them is to change their middleware to accept a Hash as a positional parameter & pass a Hash when adding their middleware (and checking for required parameters themselves). I tried an alternative to `ruby2_keywords` by adding an explicit `**kwargs` argument to `Faraday::RackBuilder#use`, `Faraday::RackBuilder#use_symbol`, `Faraday::RackBuilder::Handler#initialize`, and `Faraday::DependencyLoader#new`, but it hit the explicit delegation of keyword arguments issue (https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/#why-deprecated) in 2.6.
Configuration menu - View commit details
-
Copy full SHA for eab584e - Browse repository at this point
Copy the full SHA eab584eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 980a98b - Browse repository at this point
Copy the full SHA 980a98bView commit details -
Decrease the scope of stub middleware classes
Co-authored-by: Olle Jonsson <olle.jonsson@gmail.com>
Configuration menu - View commit details
-
Copy full SHA for 1538b70 - Browse repository at this point
Copy the full SHA 1538b70View commit details -
Configuration menu - View commit details
-
Copy full SHA for 0642990 - Browse repository at this point
Copy the full SHA 0642990View commit details -
Configuration menu - View commit details
-
Copy full SHA for 9e759f0 - Browse repository at this point
Copy the full SHA 9e759f0View commit details -
Configuration menu - View commit details
-
Copy full SHA for e8f9364 - Browse repository at this point
Copy the full SHA e8f9364View commit details -
Configuration menu - View commit details
-
Copy full SHA for b46f64d - Browse repository at this point
Copy the full SHA b46f64dView commit details -
Configuration menu - View commit details
-
Copy full SHA for c858c47 - Browse repository at this point
Copy the full SHA c858c47View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8cd00a5 - Browse repository at this point
Copy the full SHA 8cd00a5View commit details -
Configuration menu - View commit details
-
Copy full SHA for e40a305 - Browse repository at this point
Copy the full SHA e40a305View commit details -
Configuration menu - View commit details
-
Copy full SHA for 6d41c57 - Browse repository at this point
Copy the full SHA 6d41c57View commit details -
Configuration menu - View commit details
-
Copy full SHA for 385cd6d - Browse repository at this point
Copy the full SHA 385cd6dView commit details -
Let Rubocop know I'm intentionally not using the app argument for stu…
…b classes in spec
Configuration menu - View commit details
-
Copy full SHA for c97b62f - Browse repository at this point
Copy the full SHA c97b62fView commit details
Commits on May 14, 2020
-
Spec fix: derive test middleware from Faraday::Middleware
We don't have a specific base class for Request middleware like we have for response ones (Faraday::Response::Middleware), so cat_request should probably inherit from Faraday::Middleware instead.
Configuration menu - View commit details
-
Copy full SHA for faadb91 - Browse repository at this point
Copy the full SHA faadb91View commit details