Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Drop support for MRI 2.1 and MRI 2.2
We've reached to a point where we need to add a runtime dependency that
only supports MRI 2.3 or higher. I don't know how to add a runtime
dependency conditionally based on the Ruby version. Normal conditionals
won't work, because the gemspec is evaluated when the gem is built.

Since MRI 2.1 and MRI 2.2 are EOL, I see no problem dropping support for
these Rubies.
  • Loading branch information
janko committed Dec 25, 2018
1 parent dc303cb commit 267fdd4
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 113 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Expand Up @@ -3,8 +3,6 @@ language: ruby
sudo: false

rvm:
- 2.1
- 2.2
- 2.3
- 2.4
- 2.5
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,7 @@
## HEAD

* Drop support for MRI 2.1 and 2.2 (@janko-m)

* Fix `backgrounding` not working when default storage was changed with `Attachment.new` (@janko-m)

* Don't clear existing metadata definitions when loading `add_metadata` plugin (@janko-m)
Expand Down
2 changes: 1 addition & 1 deletion lib/shrine.rb
Expand Up @@ -33,7 +33,7 @@ def initialize(io, missing_methods)
size: [],
close: [],
}
deprecate_constant(:IO_METHODS) if RUBY_VERSION > "2.3"
deprecate_constant(:IO_METHODS)

@opts = {}
@storages = {}
Expand Down
10 changes: 2 additions & 8 deletions lib/shrine/plugins/_urlsafe_serialization.rb
Expand Up @@ -121,14 +121,8 @@ def json_encode(data)
JSON.generate(data)
end

if RUBY_VERSION >= "2.3"
def base64_encode(data)
Base64.urlsafe_encode64(data, padding: false)
end
else
def base64_encode(data)
Base64.urlsafe_encode64(data)
end
def base64_encode(data)
Base64.urlsafe_encode64(data, padding: false)
end

def base64_decode(data)
Expand Down
2 changes: 1 addition & 1 deletion lib/shrine/plugins/download_endpoint.rb
Expand Up @@ -132,7 +132,7 @@ def assign_download_endpoint(klass)
@download_endpoint = endpoint_class

const_set(:DownloadEndpoint, endpoint_class)
deprecate_constant(:DownloadEndpoint) if RUBY_VERSION > "2.3"
deprecate_constant(:DownloadEndpoint)
end
end

Expand Down
5 changes: 3 additions & 2 deletions lib/shrine/plugins/presign_endpoint.rb
Expand Up @@ -138,14 +138,15 @@ module ClassMethods
# Additional options can be given to override the options given on
# plugin initialization.
def presign_endpoint(storage_key, **options)
App.new({
App.new(
shrine_class: self,
storage_key: storage_key,
presign_location: opts[:presign_endpoint_presign_location],
presign_options: opts[:presign_endpoint_presign_options],
presign: opts[:presign_endpoint_presign],
rack_response: opts[:presign_endpoint_rack_response],
}.merge(options))
**options
)
end
end

Expand Down
12 changes: 3 additions & 9 deletions lib/shrine/plugins/rack_response.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require "rack"
require "content_disposition" if RUBY_VERSION >= "2.3.0"
require "content_disposition"

class Shrine
module Plugins
Expand Down Expand Up @@ -156,14 +156,8 @@ def parse_content_range(range_header)
ranges.first if ranges && ranges.one?
end

if RUBY_VERSION >= "2.3.0"
def content_disposition(disposition:, filename:)
ContentDisposition.format(disposition: disposition, filename: filename)
end
else
def content_disposition(disposition:, filename:)
"#{disposition}; filename=\"#{filename}\""
end
def content_disposition(disposition:, filename:)
ContentDisposition.format(disposition: disposition, filename: filename)
end

# Read size from metadata, otherwise retrieve the size from the storage.
Expand Down
5 changes: 3 additions & 2 deletions lib/shrine/plugins/upload_endpoint.rb
Expand Up @@ -135,14 +135,15 @@ module ClassMethods
# Additional options can be given to override the options given on
# plugin initialization.
def upload_endpoint(storage_key, **options)
App.new({
App.new(
shrine_class: self,
storage_key: storage_key,
max_size: opts[:upload_endpoint_max_size],
upload_context: opts[:upload_endpoint_upload_context],
upload: opts[:upload_endpoint_upload],
rack_response: opts[:upload_endpoint_rack_response],
}.merge(options))
**options
)
end
end

Expand Down
14 changes: 2 additions & 12 deletions lib/shrine/storage/s3.rb
Expand Up @@ -17,7 +17,7 @@
end

require "down/chunked_io"
require "content_disposition" if RUBY_VERSION >= "2.3.0"
require "content_disposition"

require "uri"
require "cgi"
Expand Down Expand Up @@ -353,7 +353,7 @@ def upload(io, id, shrine_metadata: {}, **upload_options)

options = {}
options[:content_type] = content_type if content_type
options[:content_disposition] = content_disposition(:inline, filename) if filename
options[:content_disposition] = ContentDisposition.inline(filename) if filename
options[:acl] = "public-read" if public

options.merge!(@upload_options)
Expand Down Expand Up @@ -606,16 +606,6 @@ def delete_objects(objects)
end
end

if RUBY_VERSION >= "2.3.0"
def content_disposition(disposition, filename)
ContentDisposition.format(disposition: disposition, filename: filename)
end
else
def content_disposition(disposition, filename)
"inline; filename=\"#{filename}\""
end
end

# Upload requests will fail if filename has non-ASCII characters, because
# of how S3 generates signatures, so we URI-encode them. Most browsers
# should automatically URI-decode filenames when downloading.
Expand Down
2 changes: 1 addition & 1 deletion lib/shrine/uploaded_file.rb
Expand Up @@ -92,7 +92,7 @@ def mime_type
#
# uploaded_file.open { |io| io.read } # the IO is automatically closed
def open(*args)
@io.close if @io && !(@io.respond_to?(:closed?) && @io.closed?)
@io.close if @io
@io = storage.open(id, *args)

return @io unless block_given?
Expand Down
23 changes: 7 additions & 16 deletions shrine.gemspec
Expand Up @@ -4,7 +4,7 @@ Gem::Specification.new do |gem|
gem.name = "shrine"
gem.version = Shrine.version

gem.required_ruby_version = ">= 2.1"
gem.required_ruby_version = ">= 2.3"

gem.summary = "Toolkit for file attachments in Ruby applications"
gem.description = <<-END
Expand All @@ -27,7 +27,7 @@ direct uploads for fully asynchronous user experience.
gem.require_path = "lib"

gem.add_dependency "down", "~> 4.1"
gem.add_dependency "content_disposition", "~> 1.0" if RUBY_VERSION >= "2.3.0"
gem.add_dependency "content_disposition", "~> 1.0"

gem.add_development_dependency "rake", ">= 11.1"
gem.add_development_dependency "minitest", "~> 5.8"
Expand All @@ -37,32 +37,23 @@ direct uploads for fully asynchronous user experience.
gem.add_development_dependency "shrine-memory", ">= 0.2.2"

gem.add_development_dependency "roda"
gem.add_development_dependency "rack", (RUBY_VERSION >= "2.2.2" ? "~> 2.0" : "~> 1.6")
gem.add_development_dependency "rack", "~> 2.0"
gem.add_development_dependency "mimemagic", ">= 0.3.2"
gem.add_development_dependency "marcel" if RUBY_VERSION >= "2.2.0"
gem.add_development_dependency "marcel"
gem.add_development_dependency "mime-types"
gem.add_development_dependency "mini_mime", "~> 1.0"
gem.add_development_dependency "ruby-filemagic", "~> 0.7" unless RUBY_ENGINE == "jruby" || ENV["CI"]
gem.add_development_dependency "fastimage"
gem.add_development_dependency "mini_magick", "~> 4.0" unless ENV["CI"]
gem.add_development_dependency "ruby-vips", "~> 2.0" unless ENV["CI"]
gem.add_development_dependency "aws-sdk-s3", "~> 1.16"
gem.add_development_dependency "aws-sdk-core", "~> 3.23"
gem.add_development_dependency "http-form_data", "~> 2.0"

unless RUBY_ENGINE == "jruby" || ENV["CI"]
gem.add_development_dependency "ruby-filemagic", "~> 0.7"
end

gem.add_development_dependency "sequel"

if RUBY_VERSION >= "2.2.2"
gem.add_development_dependency "activerecord", "~> 5.0"
else
gem.add_development_dependency "activerecord", "~> 4.2"
end

gem.add_development_dependency "activerecord", "~> 5.2.0"
if RUBY_ENGINE == "jruby"
gem.add_development_dependency "activerecord-jdbcsqlite3-adapter", "51"
gem.add_development_dependency "activerecord-jdbcsqlite3-adapter", "~> 52.0"
else
gem.add_development_dependency "sqlite3"
end
Expand Down
16 changes: 8 additions & 8 deletions test/file_system_test.rb
Expand Up @@ -124,7 +124,7 @@ def root_symlink

describe "#movable?" do
it "returns true for files and UploadedFiles from FileSystem" do
file = Tempfile.new("")
file = Tempfile.new
file_system_uploaded_file = @shrine.new(:file_system).upload(fakeio)
memory_uploaded_file = @shrine.new(:memory).upload(fakeio)
assert @storage.movable?(file, nil)
Expand All @@ -135,7 +135,7 @@ def root_symlink

describe "#move" do
it "moves files and UploadedFiles" do
file = Tempfile.new("")
file = Tempfile.new
uploaded_file = @shrine.new(:file_system).upload(fakeio)

@storage.move(file, "foo")
Expand All @@ -148,7 +148,7 @@ def root_symlink
end

it "creates subdirectories" do
file = Tempfile.new("")
file = Tempfile.new
uploaded_file = @shrine.new(:file_system).upload(fakeio)

@storage.move(file, "a/a/a.jpg")
Expand All @@ -166,26 +166,26 @@ def root_symlink

it "sets file permissions" do
@storage = file_system(root, permissions: 0600)
@storage.move(Tempfile.new(""), "bar.jpg")
@storage.move(Tempfile.new, "bar.jpg")
assert_permissions 0600, @storage.open("bar.jpg").path
end

it "handles file permissions being nil" do
@storage = file_system(root, permissions: nil)
@storage.move(Tempfile.new(""), "bar.jpg")
@storage.move(Tempfile.new, "bar.jpg")
end

it "sets directory permissions on intermediary directories" do
@storage = file_system(root, directory_permissions: 0777)
@storage.move(Tempfile.new(""), "a/b/c/file.jpg")
@storage.move(Tempfile.new, "a/b/c/file.jpg")
assert_permissions 0777, "#{root}/a"
assert_permissions 0777, "#{root}/a/b"
assert_permissions 0777, "#{root}/a/b/c"
end

it "handles directory permissions being nil" do
@storage = file_system(root, directory_permissions: nil)
@storage.move(Tempfile.new(""), "a/b/c/file.jpg")
@storage.move(Tempfile.new, "a/b/c/file.jpg")
end
end

Expand Down Expand Up @@ -336,7 +336,7 @@ def root_symlink
end

deprecated "#download deletes the Tempfile if an error occurs while retrieving file contents" do
tempfile = Tempfile.new("")
tempfile = Tempfile.new
Tempfile.stubs(:new).returns(tempfile)
assert_raises(Errno::ENOENT) { @storage.download("foo") }
assert tempfile.closed?
Expand Down
12 changes: 6 additions & 6 deletions test/plugin/delete_raw_test.rb
Expand Up @@ -7,24 +7,24 @@
end

it "deletes files after upload" do
@uploader.upload(tempfile = Tempfile.new(""))
@uploader.upload(tempfile = Tempfile.new)
refute File.exist?(tempfile.path)
end

it "deletes tempfiles after upload" do
@uploader.upload(file = File.open(Tempfile.new("").path))
@uploader.upload(file = File.open(Tempfile.new.path))
refute File.exist?(file.path)
end

it "deletes IOs that respond to #path after upload" do
io = FakeIO.new("file")
def io.path; (@tempfile ||= Tempfile.new("")).path; end
def io.path; (@tempfile ||= Tempfile.new).path; end
@uploader.upload(io)
refute File.exist?(io.path)
end

it "doesn't raise an error if file is already deleted" do
tempfile = Tempfile.new("")
tempfile = Tempfile.new
File.delete(tempfile.path)
@uploader.upload(tempfile)
end
Expand All @@ -41,9 +41,9 @@ def io.path; (@tempfile ||= Tempfile.new("")).path; end

it "accepts specifying storages" do
@uploader.class.plugin :delete_raw, storages: [:store]
@uploader.class.new(:cache).upload(tempfile = Tempfile.new(""))
@uploader.class.new(:cache).upload(tempfile = Tempfile.new)
assert File.exist?(tempfile.path)
@uploader.class.new(:store).upload(tempfile = Tempfile.new(""))
@uploader.class.new(:store).upload(tempfile = Tempfile.new)
refute File.exist?(tempfile.path)
end
end
2 changes: 1 addition & 1 deletion test/plugin/determine_mime_type_test.rb
Expand Up @@ -136,7 +136,7 @@
it "returns nil for empty IOs" do
assert_nil @shrine.determine_mime_type(fakeio(""))
end
end if RUBY_VERSION >= "2.2.0"
end

describe ":mime_types analyzer" do
before do
Expand Down
14 changes: 2 additions & 12 deletions test/plugin/download_endpoint_test.rb
Expand Up @@ -7,16 +7,6 @@ def app
Rack::TestApp.wrap(Rack::Lint.new(@uploader.class.download_endpoint))
end

if RUBY_VERSION >= "2.3.0"
def content_disposition(disposition, filename)
ContentDisposition.format(disposition: disposition, filename: filename)
end
else
def content_disposition(disposition, filename)
"#{disposition}; filename=\"#{filename}\""
end
end

before do
@uploader = uploader { plugin :download_endpoint }
@shrine = @uploader.class
Expand All @@ -31,14 +21,14 @@ def content_disposition(disposition, filename)
assert_equal @uploaded_file.read, response.body_binary
assert_equal @uploaded_file.size.to_s, response.headers["Content-Length"]
assert_equal @uploaded_file.mime_type, response.headers["Content-Type"]
assert_equal content_disposition(:inline, @uploaded_file.original_filename), response.headers["Content-Disposition"]
assert_equal ContentDisposition.inline(@uploaded_file.original_filename), response.headers["Content-Disposition"]
end

it "applies :disposition to response" do
@uploader = uploader { plugin :download_endpoint, disposition: "attachment" }
@uploaded_file = @uploader.upload(fakeio)
response = app.get(@uploaded_file.download_url)
assert_equal content_disposition(:attachment, @uploaded_file.id), response.headers["Content-Disposition"]
assert_equal ContentDisposition.attachment(@uploaded_file.id), response.headers["Content-Disposition"]
end

it "returns Cache-Control" do
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/rack_file_test.rb
Expand Up @@ -8,7 +8,7 @@
@shrine = @attacher.shrine_class
@rack_hash = {
name: "file",
tempfile: Tempfile.new(""),
tempfile: Tempfile.new,
filename: "image.jpg",
type: "image/jpeg",
head: "...",
Expand Down

0 comments on commit 267fdd4

Please sign in to comment.