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 019bd62 commit 90a7ea4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
## mini_portile changelog

### 2.5.3 / unreleased

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
@@ -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
@@ -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 @@ -528,6 +527,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 @@ -551,6 +551,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
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
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 90a7ea4

Please sign in to comment.