Skip to content

Commit

Permalink
refactor: apply lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuki-joto committed Oct 15, 2022
1 parent 1d2f5e3 commit 50f3114
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/previewers/heic_previewer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class HeicPreviewer < ActiveStorage::Previewer
CONTENT_TYPE = "image/heic"

Expand All @@ -7,7 +9,7 @@ def accept?(blob)
end

def minimagick_exists?
return @minimagick_exists unless @minimagick_exists.blank?
return @minimagick_exists if @minimagick_exists.present?

@minimagick_exists = defined?(ImageProcessing::MiniMagick)
Rails.logger.error "#{self.class} :: MiniMagick is not installed" unless @minimagick_exists
Expand All @@ -16,7 +18,7 @@ def minimagick_exists?
end
end

def preview(transformations)
def preview
download_blob_to_tempfile do |input|
io = ImageProcessing::MiniMagick.source(input).convert("png").call
yield io: io, filename: "#{blob.filename.base}.png", content_type: "image/png"
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/active_storage.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Rails.application.configure do
config.active_storage.previewers << HeicPreviewer
config.active_storage.variable_content_types << "image/heic"
Expand Down
4 changes: 3 additions & 1 deletion test/previewers/heic_previewer_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "test_helper"

class HeicPreviewerTest < ActiveSupport::TestCase
Expand All @@ -10,7 +12,7 @@ class HeicPreviewerTest < ActiveSupport::TestCase

blob = create_file_blob(filename: "heic-image-file.heic", content_type: CONTENT_TYPE)

refute_nil blob
assert_not_nil blob
assert HeicPreviewer.accept?(blob)

HeicPreviewer.new(blob).preview({}) do |attachable|
Expand Down

0 comments on commit 50f3114

Please sign in to comment.