Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
NARKOZ committed Feb 10, 2022
1 parent eb8bef8 commit 30e468c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
6 changes: 0 additions & 6 deletions lib/active_storage_validations/aspect_ratio_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ class AspectRatioValidator < ActiveModel::EachValidator # :nodoc
PRECISION = 3

def initialize(options)
if ActiveStorageValidations::IMAGE_PROCESSOR == :vips
require 'vips' unless defined?(Vips)
else
require 'mini_magick' unless defined?(MiniMagick)
end

super(options)
end

Expand Down
6 changes: 0 additions & 6 deletions lib/active_storage_validations/dimension_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ class DimensionValidator < ActiveModel::EachValidator # :nodoc
AVAILABLE_CHECKS = %i[width height min max].freeze

def initialize(options)
if ActiveStorageValidations::IMAGE_PROCESSOR == :vips
require 'vips' unless defined?(Vips)
else
require 'mini_magick' unless defined?(MiniMagick)
end

[:width, :height].each do |length|
if options[length] and options[length].is_a?(Hash)
if range = options[length][:in]
Expand Down
11 changes: 10 additions & 1 deletion lib/active_storage_validations/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ class Metadata
attr_reader :file

def initialize(file)
require_image_processor
@file = file
end

def image_processor
ActiveStorageValidations::IMAGE_PROCESSOR
Rails.application.config.active_storage.variant_processor
end

def require_image_processor
if image_processor == :vips
require 'vips' unless defined?(Vips)
else
require 'mini_magick' unless defined?(MiniMagick)
end
end

def metadata
Expand Down
3 changes: 0 additions & 3 deletions lib/active_storage_validations/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@

module ActiveStorageValidations
class Railtie < ::Rails::Railtie
config.after_initialize do
ActiveStorageValidations::IMAGE_PROCESSOR = Rails.application.config.active_storage.variant_processor
end
end
end

0 comments on commit 30e468c

Please sign in to comment.