Skip to content

Commit

Permalink
Merge 4badf08 into ca37a94
Browse files Browse the repository at this point in the history
  • Loading branch information
iMacTia committed Aug 8, 2021
2 parents ca37a94 + 4badf08 commit 36f68fb
Show file tree
Hide file tree
Showing 25 changed files with 78 additions and 410 deletions.
16 changes: 16 additions & 0 deletions UPGRADING.md
Expand Up @@ -31,9 +31,25 @@ We did our best to make this transition as painless as possible for you, so here
* We've setup an [Awesome Faraday](https://github.com/lostisland/awesome-faraday) repository, where you can find and discover adapters.
We also highlighted their unique features and level of compliance with Faraday's features.

### Autoloading and dependencies

Faraday has until now provided and relied on a complex dynamic dependencies system.
This would allow to reference classes and require dependencies only when needed (e.g. when running the first request) based
on the middleware/adapters used.
As part of Faraday v2.0, we've removed all external dependencies, which means we don't really need this anymore.
This change should not affect you directly, but if you're registering middleware then be aware of the new syntax:

```ruby
# `name` here can be anything you want.
# `klass` is your custom middleware class.
# This method can also be called on `Faraday::Adapter`, `Faraday::Request` and `Faraday::Response`
Faraday::Middleware.register_middleware(name: klass)
```

### Others

* Rename `Faraday::Request#method` to `#http_method`.
* Remove `Faraday::Response::Middleware`. You can now use the new `on_complete` callback provided by `Faraday::Middleware`.

## Faraday 1.0

Expand Down
9 changes: 1 addition & 8 deletions faraday.gemspec
Expand Up @@ -2,7 +2,7 @@

require_relative 'lib/faraday/version'

Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
Gem::Specification.new do |spec|
spec.name = 'faraday'
spec.version = Faraday::VERSION

Expand All @@ -15,14 +15,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength

spec.required_ruby_version = '>= 2.4'

spec.add_dependency 'faraday-em_http', '~> 1.0'
spec.add_dependency 'faraday-em_synchrony', '~> 1.0'
spec.add_dependency 'faraday-excon', '~> 1.1'
spec.add_dependency 'faraday-httpclient', '~> 1.0.1'
spec.add_dependency 'faraday-net_http', '~> 1.0'
spec.add_dependency 'faraday-net_http_persistent', '~> 1.1'
spec.add_dependency 'faraday-patron', '~> 1.0'
spec.add_dependency 'faraday-rack', '~> 1.0'
spec.add_dependency 'multipart-post', '>= 1.2', '< 3'
spec.add_dependency 'ruby2_keywords', '>= 0.0.4'

Expand Down
26 changes: 2 additions & 24 deletions lib/faraday.rb
Expand Up @@ -4,16 +4,10 @@
require 'date'
require 'set'
require 'forwardable'
require 'faraday/middleware_registry'
require 'faraday/dependency_loader'

unless defined?(::Faraday::Timer)
require 'timeout'
::Faraday::Timer = Timeout
end

require 'faraday/version'
require 'faraday/methods'
require 'faraday/error'
require 'faraday/middleware_registry'
require 'faraday/utils'
require 'faraday/options'
require 'faraday/connection'
Expand All @@ -23,7 +17,6 @@
require 'faraday/adapter'
require 'faraday/request'
require 'faraday/response'
require 'faraday/error'
require 'faraday/file_part'
require 'faraday/param_part'

Expand Down Expand Up @@ -101,19 +94,6 @@ def new(url = nil, options = {}, &block)
Faraday::Connection.new(url, options, &block)
end

# @private
# Internal: Requires internal Faraday libraries.
#
# @param libs [Array] one or more relative String names to Faraday classes.
# @return [void]
def require_libs(*libs)
libs.each do |lib|
require "#{lib_path}/#{lib}"
end
end

alias require_lib require_libs

# Documented elsewhere, see default_adapter reader
def default_adapter=(adapter)
@default_connection = nil
Expand Down Expand Up @@ -169,6 +149,4 @@ def method_missing(name, *args, &block)
self.root_path = File.expand_path __dir__
self.lib_path = File.expand_path 'faraday', __dir__
self.default_adapter = :net_http

require_lib 'autoload' unless ENV['FARADAY_NO_AUTOLOAD']
end
5 changes: 0 additions & 5 deletions lib/faraday/adapter.rb
Expand Up @@ -5,14 +5,9 @@ module Faraday
# responsible for fulfilling a Faraday request.
class Adapter
extend MiddlewareRegistry
extend DependencyLoader

CONTENT_LENGTH = 'Content-Length'

register_middleware File.expand_path('adapter', __dir__),
test: [:Test, 'test'],
typhoeus: [:Typhoeus, 'typhoeus']

# This module marks an Adapter as supporting parallel requests.
module Parallelism
attr_writer :supports_parallel
Expand Down
2 changes: 2 additions & 0 deletions lib/faraday/adapter/test.rb
Expand Up @@ -273,3 +273,5 @@ def call(env)
end
end
end

Faraday::Adapter.register_middleware(test: Faraday::Adapter::Test)
15 changes: 0 additions & 15 deletions lib/faraday/adapter/typhoeus.rb

This file was deleted.

87 changes: 0 additions & 87 deletions lib/faraday/autoload.rb

This file was deleted.

37 changes: 0 additions & 37 deletions lib/faraday/dependency_loader.rb

This file was deleted.

1 change: 1 addition & 0 deletions lib/faraday/logging/formatter.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'pp'

module Faraday
module Logging
# Serves as an integration point to customize logging
Expand Down
1 change: 0 additions & 1 deletion lib/faraday/middleware.rb
Expand Up @@ -4,7 +4,6 @@ module Faraday
# Middleware is the basic base class of any Faraday middleware.
class Middleware
extend MiddlewareRegistry
extend DependencyLoader

attr_reader :app, :options

Expand Down

0 comments on commit 36f68fb

Please sign in to comment.