Rename ActiveStorage.processor to .variant_processor

This commit is contained in:
Janko Marohnić 2018-04-22 23:40:42 +02:00
parent ca12968587
commit f01e249890
No known key found for this signature in database
GPG Key ID: 84166B4FB1C84F3E
7 changed files with 17 additions and 17 deletions

View File

@ -13,10 +13,10 @@ require "active_storage/downloading"
# {libvips}[http://jcupitt.github.io/libvips/] processor operated by the {ruby-vips}[https://github.com/jcupitt/ruby-vips]
# gem).
#
# Rails.application.config.active_storage.processor
# Rails.application.config.active_storage.variant_processor
# # => :mini_magick
#
# Rails.application.config.active_storage.processor = :vips
# Rails.application.config.active_storage.variant_processor = :vips
# # => :vips
#
# Note that to create a variant it's necessary to download the entire blob file from the service and load it

View File

@ -103,10 +103,10 @@ class ActiveStorage::Variation
image.tempfile.tap(&:open)
end
# Returns the ImageProcessing processor class specified by `ActiveStorage.processor`.
# Returns the ImageProcessing processor class specified by `ActiveStorage.variant_processor`.
def processor
require "image_processing"
ImageProcessing.const_get(ActiveStorage.processor.to_s.camelize) if ActiveStorage.processor
ImageProcessing.const_get(ActiveStorage.variant_processor.to_s.camelize) if ActiveStorage.variant_processor
rescue LoadError
ActiveSupport::Deprecation.warn("Using mini_magick gem directly is deprecated and will be removed in Rails 6.1. Please add `gem 'image_processing', '~> 1.2'` to your Gemfile.")
end

View File

@ -45,7 +45,7 @@ module ActiveStorage
mattr_accessor :queue
mattr_accessor :previewers, default: []
mattr_accessor :analyzers, default: []
mattr_accessor :processor, default: :mini_magick
mattr_accessor :variant_processor, default: :mini_magick
mattr_accessor :paths, default: {}
mattr_accessor :variable_content_types, default: []
mattr_accessor :content_types_to_serve_as_binary, default: []

View File

@ -43,12 +43,12 @@ module ActiveStorage
initializer "active_storage.configs" do
config.after_initialize do |app|
ActiveStorage.logger = app.config.active_storage.logger || Rails.logger
ActiveStorage.queue = app.config.active_storage.queue
ActiveStorage.processor = app.config.active_storage.processor || :mini_magick
ActiveStorage.previewers = app.config.active_storage.previewers || []
ActiveStorage.analyzers = app.config.active_storage.analyzers || []
ActiveStorage.paths = app.config.active_storage.paths || {}
ActiveStorage.logger = app.config.active_storage.logger || Rails.logger
ActiveStorage.queue = app.config.active_storage.queue
ActiveStorage.variant_processor = app.config.active_storage.variant_processor || :mini_magick
ActiveStorage.previewers = app.config.active_storage.previewers || []
ActiveStorage.analyzers = app.config.active_storage.analyzers || []
ActiveStorage.paths = app.config.active_storage.paths || {}
ActiveStorage.variable_content_types = app.config.active_storage.variable_content_types || []
ActiveStorage.content_types_to_serve_as_binary = app.config.active_storage.content_types_to_serve_as_binary || []

View File

@ -27,7 +27,7 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
test "center-weighted crop of JPEG blob" do
begin
ActiveStorage.processor = nil
ActiveStorage.variant_processor = nil
blob = create_file_blob(filename: "racecar.jpg")
variant = ActiveSupport::Deprecation.silence do
blob.variant(combine_options: {
@ -42,7 +42,7 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
assert_equal 100, image.width
assert_equal 100, image.height
ensure
ActiveStorage.processor = :mini_magick
ActiveStorage.variant_processor = :mini_magick
end
end
@ -90,7 +90,7 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
test "works for vips processor" do
begin
ActiveStorage.processor = :vips
ActiveStorage.variant_processor = :vips
blob = create_file_blob(filename: "racecar.jpg")
variant = blob.variant(thumbnail_image: 100).processed
@ -100,7 +100,7 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
rescue LoadError
# libvips not installed
ensure
ActiveStorage.processor = :mini_magick
ActiveStorage.variant_processor = :mini_magick
end
end
end

View File

@ -361,7 +361,7 @@ To switch to the Vips processor, you would add the following to
```ruby
# Use Vips for processing variants.
config.active_storage.processor = :vips
config.active_storage.variant_processor = :vips
```
Previewing Files

View File

@ -778,7 +778,7 @@ normal Rails server.
`config.active_storage` provides the following configuration options:
* `config.active_storage.processor` accepts a symbol `:mini_magick` or `:vips`, specifying whether variant transformations will be performed with MiniMagick or ruby-vips. The default is `:mini_magick`.
* `config.active_storage.variant_processor` accepts a symbol `:mini_magick` or `:vips`, specifying whether variant transformations will be performed with MiniMagick or ruby-vips. The default is `:mini_magick`.
* `config.active_storage.analyzers` accepts an array of classes indicating the analyzers available for Active Storage blobs. The default is `[ActiveStorage::Analyzer::ImageAnalyzer, ActiveStorage::Analyzer::VideoAnalyzer]`. The former can extract width and height of an image blob; the latter can extract width, height, duration, angle, and aspect ratio of a video blob.