Skip to content

Commit

Permalink
Add back support for MRI 2.3
Browse files Browse the repository at this point in the history
Even though Ruby 2.3 is EOL, people still on Rails 3.2.x are stuck with
Ruby 2.3, because Ruby 2.4 has some backwards incompatible changes with
the JSON gem, and possibly other problems as well.

shrinerb#365 (comment)

Since it's really not a problem for us to maintain Ruby 2.3
compatibility (at least for now), we add back support for Ruby 2.3. This
will be backported into Shrine 2.19.1 as well.
  • Loading branch information
janko committed Jul 20, 2019
1 parent eda05bc commit e86c723
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 29 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: ruby
sudo: false

rvm:
- 2.3
- 2.4
- 2.5
- 2.6
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.19.1 (2018-07-20)

* Bring back support for Ruby 2.3 (@janko)

## 2.19.0 (2019-07-18)

* `pretty_location` – Allow specifying a different identifier from `id` (@00dav00)
Expand Down
13 changes: 12 additions & 1 deletion lib/shrine/storage/file_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def method_missing(name, *args, &block)
# Cleans all empty subdirectories up the hierarchy.
def clean(path)
path.dirname.ascend do |pathname|
if Dir.empty?(pathname) && pathname != directory
if dir_empty?(pathname) && pathname != directory
pathname.rmdir
else
break
Expand Down Expand Up @@ -188,6 +188,17 @@ def list_files(directory)
.each { |path| yield path if path.file? }
end

if RUBY_VERSION >= "2.4"
def dir_empty?(path)
Dir.empty?(path)
end
else
def dir_empty?(path)
Dir.foreach(path) { |x| return false unless [".", ".."].include?(x) }
true
end
end

def deprecated_download(id, **options)
Shrine.deprecation("Shrine::Storage::FileSystem#download is deprecated and will be removed in Shrine 3.")
tempfile = Tempfile.new(["shrine-filesystem", File.extname(id)], binmode: true)
Expand Down
2 changes: 1 addition & 1 deletion shrine.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Gem::Specification.new do |gem|
gem.name = "shrine"
gem.version = Shrine.version

gem.required_ruby_version = ">= 2.4"
gem.required_ruby_version = ">= 2.3"

gem.summary = "Toolkit for file attachments in Ruby applications"
gem.description = <<-END
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/data_uri_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
assert_equal :data_uri, @event.name
assert_equal "data:image/png,content", @event[:data_uri]
assert_equal @shrine, @event[:uploader]
assert_instance_of Integer, @event.duration
assert_kind_of Integer, @event.duration
end

it "allows swapping log subscriber" do
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/derivation_endpoint_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ def upload(file, *)
assert_equal ["dark"], @event[:args]
assert_instance_of Shrine::Derivation, @event[:derivation]
assert_equal @shrine, @event[:uploader]
assert_instance_of Integer, @event.duration
assert_kind_of Integer, @event.duration
end

it "allows swapping log subscriber" do
Expand Down
8 changes: 4 additions & 4 deletions test/plugin/determine_mime_type_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@
@shrine.determine_mime_type(io = image)

refute_nil @event
assert_equal :mime_type, @event.name
assert_equal io, @event[:io]
assert_equal @shrine, @event[:uploader]
assert_instance_of Integer, @event.duration
assert_equal :mime_type, @event.name
assert_equal io, @event[:io]
assert_equal @shrine, @event[:uploader]
assert_kind_of Integer, @event.duration
end

it "allows swapping log subscriber" do
Expand Down
8 changes: 4 additions & 4 deletions test/plugin/infer_extension_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
@shrine.infer_extension("image/jpeg")

refute_nil @event
assert_equal :extension, @event.name
assert_equal "image/jpeg", @event[:mime_type]
assert_equal @shrine, @event[:uploader]
assert_instance_of Integer, @event.duration
assert_equal :extension, @event.name
assert_equal "image/jpeg", @event[:mime_type]
assert_equal @shrine, @event[:uploader]
assert_kind_of Integer, @event.duration
end

it "allows swapping log subscriber" do
Expand Down
18 changes: 9 additions & 9 deletions test/plugin/instrumentation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
@shrine.instrument(:my_event, foo: "bar") {}

assert_instance_of Dry::Events::Event, @event
assert_equal "bar", @event[:foo]
assert_instance_of Integer, @event[:time]
assert_equal "bar", @event[:foo]
assert_kind_of Integer, @event[:time]
end
end

Expand All @@ -73,7 +73,7 @@
assert_equal :my_event, @event.name
assert_equal "bar", @event[:foo]
assert_equal %i[foo time uploader], @event.payload.keys.sort
assert_instance_of Integer, @event.duration
assert_kind_of Integer, @event.duration
end

it "yields events for ActiveSupport::Notifications" do
Expand All @@ -85,7 +85,7 @@
assert_equal :my_event, @event.name
assert_equal "bar", @event[:foo]
assert_equal %i[foo uploader], @event.payload.keys.sort
assert_instance_of Integer, @event.duration
assert_kind_of Integer, @event.duration
end

it "only subscribes to events from shrine class descendants" do
Expand Down Expand Up @@ -160,7 +160,7 @@
assert_equal Hash[foo: "bar"], @event[:upload_options]
assert_equal %i[bar location metadata upload_options], @event[:options].keys.sort
assert_equal @shrine, @event[:uploader]
assert_instance_of Integer, @event[:time]
assert_kind_of Integer, @event[:time]
end

it "instruments & logs metadata events" do
Expand All @@ -181,7 +181,7 @@
assert_equal io, @event[:io]
assert_equal %i[upload_options bar], @event[:options].keys
assert_equal @shrine, @event[:uploader]
assert_instance_of Integer, @event[:time]
assert_kind_of Integer, @event[:time]
end

it "instruments & logs download events" do
Expand All @@ -199,7 +199,7 @@
assert_equal uploaded_file.id, @event[:location]
assert_equal Hash[foo: "bar"], @event[:download_options]
assert_equal @shrine, @event[:uploader]
assert_instance_of Integer, @event[:time]
assert_kind_of Integer, @event[:time]
end

it "instruments & logs exists events" do
Expand All @@ -215,7 +215,7 @@
assert_equal :store, @event[:storage]
assert_equal uploaded_file.id, @event[:location]
assert_equal @shrine, @event[:uploader]
assert_instance_of Integer, @event[:time]
assert_kind_of Integer, @event[:time]
end

it "instruments & logs delete events" do
Expand All @@ -231,7 +231,7 @@
assert_equal :store, @event[:storage]
assert_equal uploaded_file.id, @event[:location]
assert_equal @shrine, @event[:uploader]
assert_instance_of Integer, @event[:time]
assert_kind_of Integer, @event[:time]
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/plugin/remote_url_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
assert_equal good_url, @event[:remote_url]
assert_equal Hash[max_size: nil], @event[:download_options]
assert_equal @shrine, @event[:uploader]
assert_instance_of Integer, @event.duration
assert_kind_of Integer, @event.duration
end

it "allows swapping log subscriber" do
Expand Down
12 changes: 6 additions & 6 deletions test/plugin/signature_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@
@shrine.calculate_signature(io = fakeio, :md5)

refute_nil @event
assert_equal :signature, @event.name
assert_equal io, @event[:io]
assert_equal :md5, @event[:algorithm]
assert_equal :hex, @event[:format]
assert_equal @shrine, @event[:uploader]
assert_instance_of Integer, @event.duration
assert_equal :signature, @event.name
assert_equal io, @event[:io]
assert_equal :md5, @event[:algorithm]
assert_equal :hex, @event[:format]
assert_equal @shrine, @event[:uploader]
assert_kind_of Integer, @event.duration
end

it "allows swapping log subscriber" do
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/store_dimensions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
assert_equal :image_dimensions, @event.name
assert_equal io, @event[:io]
assert_equal @shrine, @event[:uploader]
assert_instance_of Integer, @event.duration
assert_kind_of Integer, @event.duration
end

it "allows swapping log subscriber" do
Expand Down

0 comments on commit e86c723

Please sign in to comment.