From 8c2907b5cc5f2e1c63bb175cafdbf11f976bfe62 Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Tue, 25 Apr 2017 18:54:19 -0300 Subject: [PATCH] Port to ruby 2.4 --- .travis.yml | 3 +- Gemfile | 4 +- Gemfile.lock | 113 ------------------ .../backends/file_system_backend.rb | 4 +- .../processors/core_image_processor.rb | 16 +-- .../attachment_fu/processors/gd2_processor.rb | 12 +- .../processors/image_science_processor.rb | 6 +- .../processors/mini_magick_processor.rb | 24 ++-- .../processors/rmagick_processor.rb | 6 +- test/backends/file_system_test.rb | 10 +- test/processors/rmagick_test.rb | 72 +++++------ test/test_helper.rb | 2 +- vendor/red_artisan/core_image/processor.rb | 26 ++-- 13 files changed, 93 insertions(+), 205 deletions(-) delete mode 100644 Gemfile.lock diff --git a/.travis.yml b/.travis.yml index 0d7ba0e5..d57b2a77 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ language: ruby rvm: - - 1.9.3 \ No newline at end of file + - 1.9.3 + - 2.4.1 diff --git a/Gemfile b/Gemfile index 2078cb46..0200e799 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,8 @@ source 'https://rubygems.org' - group :test, :development do - gem 'rails', '~> 3.2' + gem 'rails', if RUBY_VERSION >= '2.4.0' then '~> 4.2' else '~> 3.2' end + gem 'nokogiri', if RUBY_VERSION >= '2.4.0' then '~> 1.7.0' else '~> 1.6.0' end gem 'sqlite3' gem 'pothoven-attachment_fu', :path => '.' gem 'rmagick' diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index b0649313..00000000 --- a/Gemfile.lock +++ /dev/null @@ -1,113 +0,0 @@ -PATH - remote: . - specs: - pothoven-attachment_fu (3.3.0) - -GEM - remote: https://rubygems.org/ - specs: - actionmailer (3.2.14) - actionpack (= 3.2.14) - mail (~> 2.5.4) - actionpack (3.2.14) - activemodel (= 3.2.14) - activesupport (= 3.2.14) - builder (~> 3.0.0) - erubis (~> 2.7.0) - journey (~> 1.0.4) - rack (~> 1.4.5) - rack-cache (~> 1.2) - rack-test (~> 0.6.1) - sprockets (~> 2.2.1) - activemodel (3.2.14) - activesupport (= 3.2.14) - builder (~> 3.0.0) - activerecord (3.2.14) - activemodel (= 3.2.14) - activesupport (= 3.2.14) - arel (~> 3.0.2) - tzinfo (~> 0.3.29) - activeresource (3.2.14) - activemodel (= 3.2.14) - activesupport (= 3.2.14) - activesupport (3.2.14) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) - arel (3.0.2) - aws-sdk-v1 (1.61.0) - json (~> 1.4) - nokogiri (>= 1.4.4) - builder (3.0.4) - core_image (0.0.3.5) - erubis (2.7.0) - hike (1.2.3) - i18n (0.6.5) - journey (1.0.4) - json (1.8.0) - mail (2.5.4) - mime-types (~> 1.16) - treetop (~> 1.4.8) - mime-types (1.24) - mini_magick (3.6.0) - subexec (~> 0.2.1) - mini_portile (0.6.2) - multi_json (1.7.9) - nokogiri (1.6.6.2) - mini_portile (~> 0.6.0) - polyglot (0.3.3) - rack (1.4.5) - rack-cache (1.2) - rack (>= 0.4) - rack-ssl (1.3.3) - rack - rack-test (0.6.2) - rack (>= 1.0) - rails (3.2.14) - actionmailer (= 3.2.14) - actionpack (= 3.2.14) - activerecord (= 3.2.14) - activeresource (= 3.2.14) - activesupport (= 3.2.14) - bundler (~> 1.0) - railties (= 3.2.14) - railties (3.2.14) - actionpack (= 3.2.14) - activesupport (= 3.2.14) - rack-ssl (~> 1.3.2) - rake (>= 0.8.7) - rdoc (~> 3.4) - thor (>= 0.14.6, < 2.0) - rake (10.1.0) - rdoc (3.12.2) - json (~> 1.4) - rmagick (2.16.0) - sprockets (2.2.2) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - sqlite3 (1.3.8) - subexec (0.2.3) - test-unit (2.5.5) - thor (0.18.1) - tilt (1.4.1) - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) - tzinfo (0.3.37) - -PLATFORMS - ruby - -DEPENDENCIES - aws-sdk-v1 (~> 1.61.0) - core_image - mini_magick - pothoven-attachment_fu! - rails (~> 3.2) - rmagick - sqlite3 - test-unit - -BUNDLED WITH - 1.11.2 diff --git a/lib/technoweenie/attachment_fu/backends/file_system_backend.rb b/lib/technoweenie/attachment_fu/backends/file_system_backend.rb index 985fae1c..7d035a65 100644 --- a/lib/technoweenie/attachment_fu/backends/file_system_backend.rb +++ b/lib/technoweenie/attachment_fu/backends/file_system_backend.rb @@ -96,9 +96,9 @@ def destroy_file # Renames the given file before saving def rename_file return unless @old_filename && @old_filename != full_filename - if save_attachment? && File.exists?(@old_filename) + if save_attachment? && File.exist?(@old_filename) FileUtils.rm @old_filename - elsif File.exists?(@old_filename) + elsif File.exist?(@old_filename) FileUtils.mv @old_filename, full_filename end @old_filename = nil diff --git a/lib/technoweenie/attachment_fu/processors/core_image_processor.rb b/lib/technoweenie/attachment_fu/processors/core_image_processor.rb index d78e8d08..1479482a 100644 --- a/lib/technoweenie/attachment_fu/processors/core_image_processor.rb +++ b/lib/technoweenie/attachment_fu/processors/core_image_processor.rb @@ -8,13 +8,13 @@ def self.included(base) base.send :extend, ClassMethods base.alias_method_chain :process_attachment, :processing end - + module ClassMethods def with_image(file, &block) block.call OSX::CIImage.from(file) end end - + protected def process_attachment_with_processing return unless process_attachment_without_processing @@ -30,8 +30,8 @@ def process_attachment_with_processing def resize_image(img, size) processor = ::RedArtisan::CoreImage::Processor.new(img) size = size.first if size.is_a?(Array) && size.length == 1 - if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum)) - if size.is_a?(Fixnum) + if size.is_a?(Integer) || (size.is_a?(Array) && size.first.is_a?(Integer)) + if size.is_a?(Integer) processor.fit(size) else processor.resize(size[0], size[1]) @@ -40,7 +40,7 @@ def resize_image(img, size) new_size = [img.extent.size.width, img.extent.size.height] / size.to_s processor.resize(new_size[0], new_size[1]) end - + processor.render do |result| self.width = result.extent.size.width if respond_to?(:width) self.height = result.extent.size.height if respond_to?(:height) @@ -52,12 +52,12 @@ def resize_image(img, size) quality = get_jpeg_quality properties = { OSX::NSImageCompressionFactor => quality / 100.0 } if quality result.save(self.temp_path, OSX::NSJPEGFileType, properties) - # + # # puts "#{self.temp_path} @ #{quality.inspect} -> #{%x(identify -format '%Q' "#{self.temp_path}")}" - # + # self.size = File.size(self.temp_path) end - end + end end end end diff --git a/lib/technoweenie/attachment_fu/processors/gd2_processor.rb b/lib/technoweenie/attachment_fu/processors/gd2_processor.rb index ea007133..2730b872 100644 --- a/lib/technoweenie/attachment_fu/processors/gd2_processor.rb +++ b/lib/technoweenie/attachment_fu/processors/gd2_processor.rb @@ -8,7 +8,7 @@ def self.included(base) base.send :extend, ClassMethods base.alias_method_chain :process_attachment, :processing end - + module ClassMethods # Yields a block containing a GD2 Image for the given binary data. def with_image(file, &block) @@ -31,14 +31,14 @@ def process_attachment_with_processing # Performs the actual resizing operation for a thumbnail def resize_image(img, size) size = size.first if size.is_a?(Array) && size.length == 1 - if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum)) - if size.is_a?(Fixnum) - # Borrowed from image science's #thumbnail method and adapted + if size.is_a?(Integer) || (size.is_a?(Array) && size.first.is_a?(Integer)) + if size.is_a?(Integer) + # Borrowed from image science's #thumbnail method and adapted # for this. scale = size.to_f / (img.width > img.height ? img.width.to_f : img.height.to_f) img.resize!((img.width * scale).round(1), (img.height * scale).round(1), false) else - img.resize!(size.first, size.last, false) + img.resize!(size.first, size.last, false) end else w, h = [img.width, img.height] / size.to_s @@ -56,4 +56,4 @@ def resize_image(img, size) end end end -end \ No newline at end of file +end diff --git a/lib/technoweenie/attachment_fu/processors/image_science_processor.rb b/lib/technoweenie/attachment_fu/processors/image_science_processor.rb index 44da9dd0..92ab4627 100644 --- a/lib/technoweenie/attachment_fu/processors/image_science_processor.rb +++ b/lib/technoweenie/attachment_fu/processors/image_science_processor.rb @@ -52,8 +52,8 @@ def resize_image(img, size) end size = size.first if size.is_a?(Array) && size.length == 1 - if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum)) - if size.is_a?(Fixnum) + if size.is_a?(Integer) || (size.is_a?(Array) && size.first.is_a?(Integer)) + if size.is_a?(Integer) img.thumbnail(size, &grab_dimensions) else img.resize(size[0], size[1], &grab_dimensions) @@ -77,4 +77,4 @@ def resize_image(img, size) end end end -end \ No newline at end of file +end diff --git a/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb b/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb index 2a37b3ad..67259c7c 100644 --- a/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb +++ b/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb @@ -7,7 +7,7 @@ def self.included(base) base.send :extend, ClassMethods base.alias_method_chain :process_attachment, :processing end - + module ClassMethods # Yields a block containing an MiniMagick Image for the given binary data. def with_image(file, &block) @@ -23,7 +23,7 @@ def with_image(file, &block) !binary_data.nil? end end - + protected def process_attachment_with_processing return unless process_attachment_without_processing @@ -34,7 +34,7 @@ def process_attachment_with_processing callback_with_args :after_resize, img end if image? end - + # Performs the actual resizing operation for a thumbnail def resize_image(img, size) size = size.first if size.is_a?(Array) && size.length == 1 @@ -46,9 +46,9 @@ def resize_image(img, size) if format == 'GIF' img.format('PNG') end - - if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum)) - if size.is_a?(Fixnum) + + if size.is_a?(Integer) || (size.is_a?(Array) && size.first.is_a?(Integer)) + if size.is_a?(Integer) size = [size, size] commands.resize(size.join('x')) else @@ -64,16 +64,16 @@ def resize_image(img, size) # crop thumbnail, the smart way elsif size.is_a?(String) and size =~ /c$/ size = size.gsub(/c/, '') - + # calculate sizes and aspect ratio thumb_width, thumb_height = size.split("x") thumb_width = thumb_width.to_f thumb_height = thumb_height.to_f - + thumb_aspect = thumb_width.to_f / thumb_height.to_f image_width, image_height = img[:width].to_f, img[:height].to_f image_aspect = image_width / image_height - + # only crop if image is not smaller in both dimensions unless image_width < thumb_width and image_height < thumb_height command = calculate_offset(image_width,image_height,image_aspect,thumb_width,thumb_height,thumb_aspect) @@ -83,7 +83,7 @@ def resize_image(img, size) end # don not resize if image is not as height or width then thumbnail - if image_width < thumb_width or image_height < thumb_height + if image_width < thumb_width or image_height < thumb_height commands.background('#ffffff') commands.gravity('center') commands.extent(size) @@ -120,7 +120,7 @@ def calculate_offset(image_width,image_height,image_aspect,thumb_width,thumb_hei command = "#{thumb_width}x#{image_height}+#{offset}+0" # normal thumbnail generation - # calculate height and offset y, width is fixed + # calculate height and offset y, width is fixed elsif (image_aspect <= thumb_aspect or image_width < thumb_width) and image_height > thumb_height height = image_width / thumb_aspect offset = (image_height / 2) - (height / 2) @@ -139,4 +139,4 @@ def calculate_offset(image_width,image_height,image_aspect,thumb_width,thumb_hei end end end -end \ No newline at end of file +end diff --git a/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb b/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb index faa71dd9..91c5cfdc 100644 --- a/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb +++ b/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb @@ -47,9 +47,9 @@ def process_attachment_with_processing # Performs the actual resizing operation for a thumbnail def resize_image(img, size) - size = size.first if size.is_a?(Array) && size.length == 1 && !size.first.is_a?(Fixnum) - if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum)) - size = [size, size] if size.is_a?(Fixnum) + size = size.first if size.is_a?(Array) && size.length == 1 && !size.first.is_a?(Integer) + if size.is_a?(Integer) || (size.is_a?(Array) && size.first.is_a?(Integer)) + size = [size, size] if size.is_a?(Integer) img.thumbnail!(*size) elsif size.is_a?(String) && size =~ /^c.*$/ # Image cropping - example geometry string: c75x75 dimensions = size[1..size.size].split("x") diff --git a/test/backends/file_system_test.rb b/test/backends/file_system_test.rb index 88964777..5518e5f7 100644 --- a/test/backends/file_system_test.rb +++ b/test/backends/file_system_test.rb @@ -39,7 +39,7 @@ def test_should_store_file_attachment_in_filesystem(klass = FileAttachment) assert_created do attachment = upload_file :filename => '/files/rails.png' assert_valid attachment - assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist" + assert File.exist?(attachment.full_filename), "#{attachment.full_filename} does not exist" end attachment end @@ -55,8 +55,8 @@ def test_should_delete_old_file_when_updating(klass = FileAttachment) attachment.filename = 'rails2.png' attachment.temp_paths.unshift File.join(FIXTURE_PATH, file) attachment.save! - assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist" - assert !File.exists?(old_filename), "#{old_filename} still exists" + assert File.exist?(attachment.full_filename), "#{attachment.full_filename} does not exist" + assert !File.exist?(old_filename), "#{old_filename} still exists" end end end @@ -70,8 +70,8 @@ def test_should_delete_old_file_when_renaming(klass = FileAttachment) assert_not_created do attachment.filename = 'rails2.png' attachment.save - assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist" - assert !File.exists?(old_filename), "#{old_filename} still exists" + assert File.exist?(attachment.full_filename), "#{attachment.full_filename} does not exist" + assert !File.exist?(old_filename), "#{old_filename} still exists" assert !attachment.reload.size.zero? assert_equal 'rails2.png', attachment.filename end diff --git a/test/processors/rmagick_test.rb b/test/processors/rmagick_test.rb index 5d85076a..141a5e1e 100644 --- a/test/processors/rmagick_test.rb +++ b/test/processors/rmagick_test.rb @@ -16,7 +16,7 @@ def test_should_create_image_from_uploaded_file assert_equal '50x64', attachment.image_size end end - + def test_should_create_image_from_uploaded_file_with_custom_content_type assert_created do attachment = upload_file :content_type => 'foo/bar', :filename => '/files/rails.png' @@ -30,10 +30,10 @@ def test_should_create_image_from_uploaded_file_with_custom_content_type assert_equal [], attachment.thumbnails end end - + def test_should_create_thumbnail attachment = upload_file :filename => '/files/rails.png' - + assert_created do basename, ext = attachment.filename.split '.' thumbnail = attachment.create_or_update_thumbnail(attachment.create_temp_file, 'thumb', 50, 50) @@ -47,10 +47,10 @@ def test_should_create_thumbnail assert_equal "#{basename}_thumb.#{ext}", thumbnail.filename end end - + def test_should_create_thumbnail_with_geometry_strings attachment = upload_file :filename => '/files/rails.png' - + assert_created do basename, ext = attachment.filename.split '.' { 'x50' => [39, 50], '25x25!' => [25, 25] }.each do |geo, (w, h)| @@ -65,7 +65,7 @@ def test_should_create_thumbnail_with_geometry_strings end end end - + def test_should_resize_image(klass = ImageAttachment) attachment_model klass assert_equal [50, 50], attachment_model.attachment_options[:resize_to] @@ -78,9 +78,9 @@ def test_should_resize_image(klass = ImageAttachment) assert_equal 50, attachment.width assert_equal 50, attachment.height end - + test_against_subclass :test_should_resize_image, ImageAttachment - + def test_should_resize_image_with_geometry(klass = ImageOrPdfAttachment) attachment_model klass assert_equal 'x50', attachment_model.attachment_options[:resize_to] @@ -93,26 +93,26 @@ def test_should_resize_image_with_geometry(klass = ImageOrPdfAttachment) assert_equal 39, attachment.width assert_equal 50, attachment.height end - + test_against_subclass :test_should_resize_image_with_geometry, ImageOrPdfAttachment - + def test_should_give_correct_thumbnail_filenames(klass = ImageWithThumbsFileAttachment) attachment_model klass assert_created 3 do attachment = upload_file :filename => '/files/rails.png' thumb = attachment.thumbnails.detect { |t| t.filename =~ /_thumb/ } geo = attachment.thumbnails.detect { |t| t.filename =~ /_geometry/ } - + [attachment, thumb, geo].each { |record| assert_valid record } - + assert_match /rails\.png$/, attachment.full_filename assert_match /rails_geometry\.png$/, attachment.full_filename(:geometry) assert_match /rails_thumb\.png$/, attachment.full_filename(:thumb) end end - + test_against_subclass :test_should_give_correct_thumbnail_filenames, ImageWithThumbsFileAttachment - + def test_should_automatically_create_thumbnails(klass = ImageWithThumbsAttachment) attachment_model klass assert_created 3 do @@ -124,7 +124,7 @@ def test_should_automatically_create_thumbnails(klass = ImageWithThumbsAttachmen assert_equal 55, attachment.height assert_equal 2, attachment.thumbnails.length # assert_equal 1.0, attachment.aspect_ratio - + thumb = attachment.thumbnails.detect { |t| t.filename =~ /_thumb/ } assert !thumb.new_record?, thumb.errors.full_messages.join("\n") assert !thumb.size.zero? @@ -132,7 +132,7 @@ def test_should_automatically_create_thumbnails(klass = ImageWithThumbsAttachmen assert_equal 50, thumb.width assert_equal 50, thumb.height # assert_equal 1.0, thumb.aspect_ratio - + geo = attachment.thumbnails.detect { |t| t.filename =~ /_geometry/ } assert !geo.new_record?, geo.errors.full_messages.join("\n") assert !geo.size.zero? @@ -142,12 +142,12 @@ def test_should_automatically_create_thumbnails(klass = ImageWithThumbsAttachmen # assert_equal 1.0, geo.aspect_ratio end end - + test_against_subclass :test_should_automatically_create_thumbnails, ImageWithThumbsAttachment - + # same as above method, but test it on a file model test_against_class :test_should_automatically_create_thumbnails, ImageWithThumbsFileAttachment - + def test_should_use_thumbnail_subclass(klass = ImageWithThumbsClassFileAttachment) attachment_model klass attachment = nil @@ -165,16 +165,16 @@ def test_should_use_thumbnail_subclass(klass = ImageWithThumbsClassFileAttachmen "#full_filename does not use thumbnail class' path." assert_equal attachment.destroy, attachment end - + test_against_subclass :test_should_use_thumbnail_subclass, ImageWithThumbsClassFileAttachment - + def test_should_remove_old_thumbnail_files_when_updating(klass = ImageWithThumbsFileAttachment) attachment_model klass attachment = nil assert_created 3 do attachment = upload_file :filename => '/files/rails.png' end - + old_filenames = [attachment.full_filename] + attachment.thumbnails.collect(&:full_filename) use_temp_file 'files/rails.jpg' do |file| @@ -183,31 +183,31 @@ def test_should_remove_old_thumbnail_files_when_updating(klass = ImageWithThumbs end new_filenames = [attachment.reload.full_filename] + attachment.thumbnails.collect { |t| t.reload.full_filename } - new_filenames.each { |f| assert File.exists?(f), "#{f} does not exist" } - old_filenames.each { |f| assert !File.exists?(f), "#{f} still exists" } + new_filenames.each { |f| assert File.exist?(f), "#{f} does not exist" } + old_filenames.each { |f| assert !File.exist?(f), "#{f} still exists" } end - + test_against_subclass :test_should_remove_old_thumbnail_files_when_updating, ImageWithThumbsFileAttachment - + def test_should_delete_file_when_in_file_system_when_attachment_record_destroyed(klass = ImageWithThumbsFileAttachment) attachment_model klass attachment = upload_file :filename => '/files/rails.png' filenames = [attachment.full_filename] + attachment.thumbnails.collect(&:full_filename) - filenames.each { |f| assert File.exists?(f), "#{f} never existed to delete on destroy" } + filenames.each { |f| assert File.exist?(f), "#{f} never existed to delete on destroy" } attachment.destroy - filenames.each { |f| assert !File.exists?(f), "#{f} still exists" } + filenames.each { |f| assert !File.exist?(f), "#{f} still exists" } end - + test_against_subclass :test_should_delete_file_when_in_file_system_when_attachment_record_destroyed, ImageWithThumbsFileAttachment - + def test_should_have_full_filename_method(klass = FileAttachment) attachment_model klass attachment = upload_file :filename => '/files/rails.png' assert_respond_to attachment, :full_filename end - + test_against_subclass :test_should_have_full_filename_method, FileAttachment - + def test_should_overwrite_old_thumbnail_records_when_updating(klass = ImageWithThumbsAttachment) attachment_model klass attachment = nil @@ -217,7 +217,7 @@ def test_should_overwrite_old_thumbnail_records_when_updating(klass = ImageWithT assert_not_created do # no new db_file records use_temp_file "files/rails.png" do |file| attachment.filename = 'rails2.png' - # The above test (#test_should_have_full_filename_method) to pass before be can set the temp_path below -- + # The above test (#test_should_have_full_filename_method) to pass before be can set the temp_path below -- # #temp_path calls #full_filename, which is not getting mixed into the attachment. Maybe we don't need to # set temp_path at all? # @@ -226,9 +226,9 @@ def test_should_overwrite_old_thumbnail_records_when_updating(klass = ImageWithT end end end - + test_against_subclass :test_should_overwrite_old_thumbnail_records_when_updating, ImageWithThumbsAttachment - + def test_should_overwrite_old_thumbnail_records_when_renaming(klass = ImageWithThumbsAttachment) attachment_model klass attachment = nil @@ -242,7 +242,7 @@ def test_should_overwrite_old_thumbnail_records_when_renaming(klass = ImageWithT assert_equal 'rails2.png', attachment.filename end end - + test_against_subclass :test_should_overwrite_old_thumbnail_records_when_renaming, ImageWithThumbsAttachment def test_should_handle_jpeg_quality diff --git a/test/test_helper.rb b/test/test_helper.rb index 64d21563..c09c2f26 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -117,7 +117,7 @@ def assert_file_jpeg_quality(model, thumbnail, expected) filename = if model.respond_to?(:full_filename) model.full_filename(thumbnail) else - thumb = thumbnail ? model.thumbnails.find(:first, :conditions => { :thumbnail => thumbnail.to_s }, :include => :db_file) : model + thumb = thumbnail ? model.thumbnails.includes(:db_file).where(thumbnail: thumbnail.to_s).first : model unless thumb && thumb.db_file && thumb.db_file.data && thumb.db_file.data.size > 0 STDERR.puts "Cannot find DB file data for thumbnail #{thumbnail.inspect} -> Aborting JPEG quality check." return diff --git a/vendor/red_artisan/core_image/processor.rb b/vendor/red_artisan/core_image/processor.rb index 965e70cc..750f3ffa 100644 --- a/vendor/red_artisan/core_image/processor.rb +++ b/vendor/red_artisan/core_image/processor.rb @@ -58,7 +58,7 @@ module RedArtisan module CoreImage class Processor - + def initialize(original) if original.respond_to? :to_str @original = OSX::CIImage.from(original.to_str) @@ -66,23 +66,23 @@ def initialize(original) @original = original end end - + def render(&block) raise "unprocessed image: #{@original}" unless @target block.call @target end - + include Filters::Scale, Filters::Color, Filters::Watermark, Filters::Quality, Filters::Perspective, Filters::Effects - + private - + def create_core_image_context(width, height) output = OSX::NSBitmapImageRep.alloc.initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel(nil, width, height, 8, 4, true, false, OSX::NSDeviceRGBColorSpace, 0, 0) context = OSX::NSGraphicsContext.graphicsContextWithBitmapImageRep(output) OSX::NSGraphicsContext.setCurrentContext(context) @ci_context = context.CIContext end - + def vector(x, y, w, h) OSX::CIVector.vectorWithX_Y_Z_W(x, y, w, h) end @@ -93,29 +93,29 @@ def vector(x, y, w, h) module OSX class CIImage include OCObjWrapper - + def method_missing_with_filter_processing(sym, *args, &block) f = OSX::CIFilter.filterWithName("CI#{sym.to_s.camelize}") return method_missing_without_filter_processing(sym, *args, &block) unless f - + f.setDefaults if f.respond_to? :setDefaults f.setValue_forKey(self, 'inputImage') options = args.last.is_a?(Hash) ? args.last : {} options.each { |k, v| f.setValue_forKey(v, k.to_s) } - + block.call f.valueForKey('outputImage') end - + alias_method_chain :method_missing, :filter_processing - + def save(target, format = OSX::NSJPEGFileType, properties = nil) bitmapRep = OSX::NSBitmapImageRep.alloc.initWithCIImage(self) blob = bitmapRep.representationUsingType_properties(format, properties) blob.writeToFile_atomically(target, false) end - + def self.from(filepath) - raise Errno::ENOENT, "No such file or directory - #{filepath}" unless File.exists?(filepath) + raise Errno::ENOENT, "No such file or directory - #{filepath}" unless File.exist?(filepath) OSX::CIImage.imageWithContentsOfURL(OSX::NSURL.fileURLWithPath(filepath)) end end