Skip to content

Commit

Permalink
dep: make net-ftp an optional dependency
Browse files Browse the repository at this point in the history
and let users know what's wrong if they try to use it with a version
of Ruby that doesn't provide it by default.
  • Loading branch information
flavorjones committed May 31, 2021
1 parent 8f49bfa commit 863da5e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ particular, this may be useful for debugging problems with the upstream dependen
bisect` in a local clone) or for continuous integration with upstream HEAD.


### 2.5.3 / 2021-05-31

Make `net-ftp` an optional dependency, since requiring it as a hard dependency in v2.5.2 caused warnings to be emitted by Ruby 2.7 and earlier. A warning message is emitted if FTP functionality is called and `net-ftp` isn't available; this should only happen in Ruby 3.1 and later.


### 2.5.2 / 2021-05-28

#### Dependencies
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
source 'https://rubygems.org'

gem "net-ftp" if Gem::Requirement.new("> 3.1.0.dev").satisfied_by?(Gem::Version.new(RUBY_VERSION))

# Specify your gem's dependencies in mini_portile2.gemspec
gemspec
4 changes: 3 additions & 1 deletion lib/mini_portile2/mini_portile.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'rbconfig'
require 'net/http'
require 'net/https'
require 'net/ftp'
require 'fileutils'
require 'tempfile'
require 'digest'
Expand Down Expand Up @@ -545,6 +544,7 @@ def download_file_file(uri, full_path)
end

def download_file_ftp(uri, full_path)
require "net/ftp"
filename = File.basename(uri.path)
with_tempfile(filename, full_path) do |temp_file|
total = 0
Expand All @@ -568,6 +568,8 @@ def download_file_ftp(uri, full_path)
end
output
end
rescue LoadError
raise LoadError, "Ruby #{RUBY_VERSION} does not provide the net-ftp gem, please add it as a dependency if you need to use FTP"
rescue Net::FTPError
return false
end
Expand Down
2 changes: 0 additions & 2 deletions mini_portile2.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = ">= 2.3.0"

spec.add_dependency "net-ftp", "~> 0.1"

spec.add_development_dependency "bundler", "~> 2.1"
spec.add_development_dependency "minitar", "~> 0.7"
spec.add_development_dependency "minitest", "~> 5.11"
Expand Down
10 changes: 6 additions & 4 deletions test/test_download.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ def server_must_receive_connection(connections = 3, &block)
end
end

block.call

thread.kill
server.close
begin
block.call
ensure
thread.kill
server.close
end

request_count.must_be :>, 0
end
Expand Down

0 comments on commit 863da5e

Please sign in to comment.