Skip to content

Commit 2abe947

Browse files
committed
Port to ruby 2.4
1 parent bee47d6 commit 2abe947

File tree

13 files changed

+93
-205
lines changed

13 files changed

+93
-205
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
language: ruby
22
rvm:
3-
- 1.9.3
3+
- 1.9.3
4+
- 2.4.1

Gemfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
source 'https://rubygems.org'
22

3-
43
group :test, :development do
5-
gem 'rails', '~> 3.2'
4+
gem 'rails', if RUBY_VERSION >= '2.4.0' then '~> 4.2' else '~> 3.2' end
5+
gem 'nokogiri', if RUBY_VERSION >= '2.4.0' then '~> 1.7.0' else '~> 1.6.0' end
66
gem 'sqlite3'
77
gem 'pothoven-attachment_fu', :path => '.'
88
gem 'rmagick'

Gemfile.lock

-113
This file was deleted.

lib/technoweenie/attachment_fu/backends/file_system_backend.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ def destroy_file
9696
# Renames the given file before saving
9797
def rename_file
9898
return unless @old_filename && @old_filename != full_filename
99-
if save_attachment? && File.exists?(@old_filename)
99+
if save_attachment? && File.exist?(@old_filename)
100100
FileUtils.rm @old_filename
101-
elsif File.exists?(@old_filename)
101+
elsif File.exist?(@old_filename)
102102
FileUtils.mv @old_filename, full_filename
103103
end
104104
@old_filename = nil

lib/technoweenie/attachment_fu/processors/core_image_processor.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ def self.included(base)
88
base.send :extend, ClassMethods
99
base.alias_method_chain :process_attachment, :processing
1010
end
11-
11+
1212
module ClassMethods
1313
def with_image(file, &block)
1414
block.call OSX::CIImage.from(file)
1515
end
1616
end
17-
17+
1818
protected
1919
def process_attachment_with_processing
2020
return unless process_attachment_without_processing
@@ -30,8 +30,8 @@ def process_attachment_with_processing
3030
def resize_image(img, size)
3131
processor = ::RedArtisan::CoreImage::Processor.new(img)
3232
size = size.first if size.is_a?(Array) && size.length == 1
33-
if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
34-
if size.is_a?(Fixnum)
33+
if size.is_a?(Integer) || (size.is_a?(Array) && size.first.is_a?(Integer))
34+
if size.is_a?(Integer)
3535
processor.fit(size)
3636
else
3737
processor.resize(size[0], size[1])
@@ -40,7 +40,7 @@ def resize_image(img, size)
4040
new_size = [img.extent.size.width, img.extent.size.height] / size.to_s
4141
processor.resize(new_size[0], new_size[1])
4242
end
43-
43+
4444
processor.render do |result|
4545
self.width = result.extent.size.width if respond_to?(:width)
4646
self.height = result.extent.size.height if respond_to?(:height)
@@ -52,12 +52,12 @@ def resize_image(img, size)
5252
quality = get_jpeg_quality
5353
properties = { OSX::NSImageCompressionFactor => quality / 100.0 } if quality
5454
result.save(self.temp_path, OSX::NSJPEGFileType, properties)
55-
#
55+
#
5656
# puts "#{self.temp_path} @ #{quality.inspect} -> #{%x(identify -format '%Q' "#{self.temp_path}")}"
57-
#
57+
#
5858
self.size = File.size(self.temp_path)
5959
end
60-
end
60+
end
6161
end
6262
end
6363
end

lib/technoweenie/attachment_fu/processors/gd2_processor.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def self.included(base)
88
base.send :extend, ClassMethods
99
base.alias_method_chain :process_attachment, :processing
1010
end
11-
11+
1212
module ClassMethods
1313
# Yields a block containing a GD2 Image for the given binary data.
1414
def with_image(file, &block)
@@ -31,14 +31,14 @@ def process_attachment_with_processing
3131
# Performs the actual resizing operation for a thumbnail
3232
def resize_image(img, size)
3333
size = size.first if size.is_a?(Array) && size.length == 1
34-
if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
35-
if size.is_a?(Fixnum)
36-
# Borrowed from image science's #thumbnail method and adapted
34+
if size.is_a?(Integer) || (size.is_a?(Array) && size.first.is_a?(Integer))
35+
if size.is_a?(Integer)
36+
# Borrowed from image science's #thumbnail method and adapted
3737
# for this.
3838
scale = size.to_f / (img.width > img.height ? img.width.to_f : img.height.to_f)
3939
img.resize!((img.width * scale).round(1), (img.height * scale).round(1), false)
4040
else
41-
img.resize!(size.first, size.last, false)
41+
img.resize!(size.first, size.last, false)
4242
end
4343
else
4444
w, h = [img.width, img.height] / size.to_s
@@ -56,4 +56,4 @@ def resize_image(img, size)
5656
end
5757
end
5858
end
59-
end
59+
end

lib/technoweenie/attachment_fu/processors/image_science_processor.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def resize_image(img, size)
5252
end
5353

5454
size = size.first if size.is_a?(Array) && size.length == 1
55-
if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
56-
if size.is_a?(Fixnum)
55+
if size.is_a?(Integer) || (size.is_a?(Array) && size.first.is_a?(Integer))
56+
if size.is_a?(Integer)
5757
img.thumbnail(size, &grab_dimensions)
5858
else
5959
img.resize(size[0], size[1], &grab_dimensions)
@@ -77,4 +77,4 @@ def resize_image(img, size)
7777
end
7878
end
7979
end
80-
end
80+
end

lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb

+12-12
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def self.included(base)
77
base.send :extend, ClassMethods
88
base.alias_method_chain :process_attachment, :processing
99
end
10-
10+
1111
module ClassMethods
1212
# Yields a block containing an MiniMagick Image for the given binary data.
1313
def with_image(file, &block)
@@ -23,7 +23,7 @@ def with_image(file, &block)
2323
!binary_data.nil?
2424
end
2525
end
26-
26+
2727
protected
2828
def process_attachment_with_processing
2929
return unless process_attachment_without_processing
@@ -34,7 +34,7 @@ def process_attachment_with_processing
3434
callback_with_args :after_resize, img
3535
end if image?
3636
end
37-
37+
3838
# Performs the actual resizing operation for a thumbnail
3939
def resize_image(img, size)
4040
size = size.first if size.is_a?(Array) && size.length == 1
@@ -46,9 +46,9 @@ def resize_image(img, size)
4646
if format == 'GIF'
4747
img.format('PNG')
4848
end
49-
50-
if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
51-
if size.is_a?(Fixnum)
49+
50+
if size.is_a?(Integer) || (size.is_a?(Array) && size.first.is_a?(Integer))
51+
if size.is_a?(Integer)
5252
size = [size, size]
5353
commands.resize(size.join('x'))
5454
else
@@ -64,16 +64,16 @@ def resize_image(img, size)
6464
# crop thumbnail, the smart way
6565
elsif size.is_a?(String) and size =~ /c$/
6666
size = size.gsub(/c/, '')
67-
67+
6868
# calculate sizes and aspect ratio
6969
thumb_width, thumb_height = size.split("x")
7070
thumb_width = thumb_width.to_f
7171
thumb_height = thumb_height.to_f
72-
72+
7373
thumb_aspect = thumb_width.to_f / thumb_height.to_f
7474
image_width, image_height = img[:width].to_f, img[:height].to_f
7575
image_aspect = image_width / image_height
76-
76+
7777
# only crop if image is not smaller in both dimensions
7878
unless image_width < thumb_width and image_height < thumb_height
7979
command = calculate_offset(image_width,image_height,image_aspect,thumb_width,thumb_height,thumb_aspect)
@@ -83,7 +83,7 @@ def resize_image(img, size)
8383
end
8484

8585
# don not resize if image is not as height or width then thumbnail
86-
if image_width < thumb_width or image_height < thumb_height
86+
if image_width < thumb_width or image_height < thumb_height
8787
commands.background('#ffffff')
8888
commands.gravity('center')
8989
commands.extent(size)
@@ -120,7 +120,7 @@ def calculate_offset(image_width,image_height,image_aspect,thumb_width,thumb_hei
120120
command = "#{thumb_width}x#{image_height}+#{offset}+0"
121121

122122
# normal thumbnail generation
123-
# calculate height and offset y, width is fixed
123+
# calculate height and offset y, width is fixed
124124
elsif (image_aspect <= thumb_aspect or image_width < thumb_width) and image_height > thumb_height
125125
height = image_width / thumb_aspect
126126
offset = (image_height / 2) - (height / 2)
@@ -139,4 +139,4 @@ def calculate_offset(image_width,image_height,image_aspect,thumb_width,thumb_hei
139139
end
140140
end
141141
end
142-
end
142+
end

lib/technoweenie/attachment_fu/processors/rmagick_processor.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def process_attachment_with_processing
4747

4848
# Performs the actual resizing operation for a thumbnail
4949
def resize_image(img, size)
50-
size = size.first if size.is_a?(Array) && size.length == 1 && !size.first.is_a?(Fixnum)
51-
if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
52-
size = [size, size] if size.is_a?(Fixnum)
50+
size = size.first if size.is_a?(Array) && size.length == 1 && !size.first.is_a?(Integer)
51+
if size.is_a?(Integer) || (size.is_a?(Array) && size.first.is_a?(Integer))
52+
size = [size, size] if size.is_a?(Integer)
5353
img.thumbnail!(*size)
5454
elsif size.is_a?(String) && size =~ /^c.*$/ # Image cropping - example geometry string: c75x75
5555
dimensions = size[1..size.size].split("x")

test/backends/file_system_test.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_should_store_file_attachment_in_filesystem(klass = FileAttachment)
3939
assert_created do
4040
attachment = upload_file :filename => '/files/rails.png'
4141
assert_valid attachment
42-
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
42+
assert File.exist?(attachment.full_filename), "#{attachment.full_filename} does not exist"
4343
end
4444
attachment
4545
end
@@ -55,8 +55,8 @@ def test_should_delete_old_file_when_updating(klass = FileAttachment)
5555
attachment.filename = 'rails2.png'
5656
attachment.temp_paths.unshift File.join(FIXTURE_PATH, file)
5757
attachment.save!
58-
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
59-
assert !File.exists?(old_filename), "#{old_filename} still exists"
58+
assert File.exist?(attachment.full_filename), "#{attachment.full_filename} does not exist"
59+
assert !File.exist?(old_filename), "#{old_filename} still exists"
6060
end
6161
end
6262
end
@@ -70,8 +70,8 @@ def test_should_delete_old_file_when_renaming(klass = FileAttachment)
7070
assert_not_created do
7171
attachment.filename = 'rails2.png'
7272
attachment.save
73-
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
74-
assert !File.exists?(old_filename), "#{old_filename} still exists"
73+
assert File.exist?(attachment.full_filename), "#{attachment.full_filename} does not exist"
74+
assert !File.exist?(old_filename), "#{old_filename} still exists"
7575
assert !attachment.reload.size.zero?
7676
assert_equal 'rails2.png', attachment.filename
7777
end

0 commit comments

Comments
 (0)