Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Replace cocaine to terrapin #2553

Merged
merged 1 commit into from
Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
require 'mimemagic'
require 'mimemagic/overlay'
require 'logger'
require 'cocaine'
require 'terrapin'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.


require 'paperclip/railtie' if defined?(Rails::Railtie)

Expand Down
2 changes: 1 addition & 1 deletion lib/paperclip/file_command_content_type_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def type_from_file_command
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
type = begin
Paperclip.run("file", "-b --mime :file", file: @filename)
rescue Cocaine::CommandLineError => e
rescue Terrapin::CommandLineError => e
Paperclip.log("Error while determining content type: #{e}")
SENSIBLE_DEFAULT
end
Expand Down
4 changes: 2 additions & 2 deletions lib/paperclip/geometry_detector_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def geometry_string
:swallow_stderr => true
}
)
rescue Cocaine::ExitStatusError
rescue Terrapin::ExitStatusError
""
rescue Cocaine::CommandNotFoundError => e
rescue Terrapin::CommandNotFoundError => e

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless assignment to variable - e.

raise_because_imagemagick_missing
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/paperclip/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def interpolates key, &block
#
def run(cmd, arguments = "", interpolation_values = {}, local_options = {})
command_path = options[:command_path]
cocaine_path_array = Cocaine::CommandLine.path.try(:split, Cocaine::OS.path_separator)
Cocaine::CommandLine.path = [cocaine_path_array, command_path].flatten.compact.uniq
terrapin_path_array = Terrapin::CommandLine.path.try(:split, Terrapin::OS.path_separator)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [95/80]

Terrapin::CommandLine.path = [terrapin_path_array, command_path].flatten.compact.uniq

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [91/80]

if logging? && (options[:log_command] || local_options[:log_command])
local_options = local_options.merge(:logger => logger)
end
Cocaine::CommandLine.new(cmd, arguments, local_options).run(interpolation_values)
Terrapin::CommandLine.new(cmd, arguments, local_options).run(interpolation_values)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [88/80]

end

# Find all instances of the given Active Record model +klass+ with attachment +name+.
Expand Down
2 changes: 1 addition & 1 deletion lib/paperclip/media_type_spoof_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def type_from_file_command
begin
Paperclip.run("file", "-b --mime :file", file: @file.path).
split(/[:;\s]+/).first
rescue Cocaine::CommandLineError
rescue Terrapin::CommandLineError
""
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/paperclip/thumbnail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def make
source: "#{File.expand_path(src.path)}#{frame}",
dest: File.expand_path(dst.path),
)
rescue Cocaine::ExitStatusError => e
rescue Terrapin::ExitStatusError => e

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless assignment to variable - e.

raise Paperclip::Error, "There was an error processing the thumbnail for #{@basename}" if @whiny
rescue Cocaine::CommandNotFoundError => e
rescue Terrapin::CommandNotFoundError => e

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless assignment to variable - e.

raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `convert` command. Please install ImageMagick.")
end

Expand Down Expand Up @@ -122,9 +122,9 @@ def identified_as_animated?
@identified_as_animated = ANIMATED_FORMATS.include? identify("-format %m :file", :file => "#{@file.path}[0]").to_s.downcase.strip
end
@identified_as_animated
rescue Cocaine::ExitStatusError => e
rescue Terrapin::ExitStatusError => e

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless assignment to variable - e.

raise Paperclip::Error, "There was an error running `identify` for #{@basename}" if @whiny
rescue Cocaine::CommandNotFoundError => e
rescue Terrapin::CommandNotFoundError => e

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless assignment to variable - e.

raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `identify` command. Please install ImageMagick.")
end
end
Expand Down
2 changes: 1 addition & 1 deletion paperclip.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Gem::Specification.new do |s|

s.add_dependency('activemodel', '>= 4.2.0')
s.add_dependency('activesupport', '>= 4.2.0')
s.add_dependency('cocaine', '~> 0.5.5')
s.add_dependency('terrapin', '~> 0.6.0')
s.add_dependency('mime-types')
s.add_dependency('mimemagic', '~> 0.3.0')

Expand Down
2 changes: 1 addition & 1 deletion spec/paperclip/content_type_detector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
end

it 'returns a sensible default when the file command is missing' do
Paperclip.stubs(:run).raises(Cocaine::CommandLineError.new)
Paperclip.stubs(:run).raises(Terrapin::CommandLineError.new)
@filename = "/path/to/something"
assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
end
Expand Down
2 changes: 1 addition & 1 deletion spec/paperclip/file_command_content_type_detector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

it 'returns a sensible default when the file command is missing' do
Paperclip.stubs(:run).raises(Cocaine::CommandLineError.new)
Paperclip.stubs(:run).raises(Terrapin::CommandLineError.new)
@filename = "/path/to/something"
assert_equal "application/octet-stream",
Paperclip::FileCommandContentTypeDetector.new(@filename).detect
Expand Down
26 changes: 13 additions & 13 deletions spec/paperclip/paperclip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,40 @@
context ".run" do
before do
Paperclip.options[:log_command] = false
Cocaine::CommandLine.expects(:new).with("convert", "stuff", {}).returns(stub(:run))
@original_command_line_path = Cocaine::CommandLine.path
Terrapin::CommandLine.expects(:new).with("convert", "stuff", {}).returns(stub(:run))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [90/80]

@original_command_line_path = Terrapin::CommandLine.path
end

after do
Paperclip.options[:log_command] = true
Cocaine::CommandLine.path = @original_command_line_path
Terrapin::CommandLine.path = @original_command_line_path
end

it "runs the command with Cocaine" do
it "runs the command with Terrapin" do
Paperclip.run("convert", "stuff")
end

it "saves Cocaine::CommandLine.path that set before" do
Cocaine::CommandLine.path = "/opt/my_app/bin"
it "saves Terrapin::CommandLine.path that set before" do
Terrapin::CommandLine.path = "/opt/my_app/bin"
Paperclip.run("convert", "stuff")
expect(Cocaine::CommandLine.path).to match("/opt/my_app/bin")
expect(Terrapin::CommandLine.path).to match("/opt/my_app/bin")
end

it "does not duplicate Cocaine::CommandLine.path on multiple runs" do
Cocaine::CommandLine.expects(:new).with("convert", "more_stuff", {}).returns(stub(:run))
Cocaine::CommandLine.path = nil
it "does not duplicate Terrapin::CommandLine.path on multiple runs" do
Terrapin::CommandLine.expects(:new).with("convert", "more_stuff", {}).returns(stub(:run))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [95/80]

Terrapin::CommandLine.path = nil
Paperclip.options[:command_path] = "/opt/my_app/bin"
Paperclip.run("convert", "stuff")
Paperclip.run("convert", "more_stuff")

cmd_path = Paperclip.options[:command_path]
assert_equal 1, Cocaine::CommandLine.path.scan(cmd_path).count
assert_equal 1, Terrapin::CommandLine.path.scan(cmd_path).count
end
end

it 'does not raise errors when doing a lot of running' do
Paperclip.options[:command_path] = ["/usr/local/bin"] * 1024
Cocaine::CommandLine.path = "/something/else"
Terrapin::CommandLine.path = "/something/else"
100.times do |x|
Paperclip.run("echo", x.to_s)
end
Expand All @@ -63,7 +63,7 @@
context "Calling Paperclip.run with a logger" do
it "passes the defined logger if :log_command is set" do
Paperclip.options[:log_command] = true
Cocaine::CommandLine.expects(:new).with("convert", "stuff", logger: Paperclip.logger).returns(stub(:run))
Terrapin::CommandLine.expects(:new).with("convert", "stuff", logger: Paperclip.logger).returns(stub(:run))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [112/80]

Paperclip.run("convert", "stuff")
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/paperclip/processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
end

context "Calling #convert" do
it "runs the convert command with Cocaine" do
it "runs the convert command with Terrapin" do
Paperclip.options[:log_command] = false
Cocaine::CommandLine.expects(:new).with("convert", "stuff", {}).returns(stub(:run))
Terrapin::CommandLine.expects(:new).with("convert", "stuff", {}).returns(stub(:run))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [90/80]

Paperclip::Processor.new('filename').convert("stuff")
end
end

context "Calling #identify" do
it "runs the identify command with Cocaine" do
it "runs the identify command with Terrapin" do
Paperclip.options[:log_command] = false
Cocaine::CommandLine.expects(:new).with("identify", "stuff", {}).returns(stub(:run))
Terrapin::CommandLine.expects(:new).with("identify", "stuff", {}).returns(stub(:run))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [91/80]

Paperclip::Processor.new('filename').identify("stuff")
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/paperclip/thumbnail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
it "lets us know when a command isn't found versus a processing error" do
old_path = ENV['PATH']
begin
Cocaine::CommandLine.path = ''
Terrapin::CommandLine.path = ''

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Paperclip.options[:command_path] = ''
ENV['PATH'] = ''
assert_raises(Paperclip::Errors::CommandNotFoundError) do
Expand Down Expand Up @@ -102,7 +102,7 @@

output_file = thumb.make

command = Cocaine::CommandLine.new("identify", "-format %wx%h :file")
command = Terrapin::CommandLine.new("identify", "-format %wx%h :file")
assert_equal "50x50", command.run(file: output_file.path).strip
end

Expand Down Expand Up @@ -189,7 +189,7 @@
it "lets us know when a command isn't found versus a processing error" do
old_path = ENV['PATH']
begin
Cocaine::CommandLine.path = ''
Terrapin::CommandLine.path = ''

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Paperclip.options[:command_path] = ''
ENV['PATH'] = ''
assert_raises(Paperclip::Errors::CommandNotFoundError) do
Expand Down