mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make processing an explicit step
This commit is contained in:
parent
6c2cef21ce
commit
af99968112
2 changed files with 9 additions and 7 deletions
|
@ -13,8 +13,8 @@ class ActiveStorage::Variant
|
|||
attr_reader :blob, :variation
|
||||
delegate :service, to: :blob
|
||||
|
||||
def self.find_or_create_by(blob_key:, variation_key:)
|
||||
new ActiveStorage::Blob.find_by!(key: blob_key), variation: verifier.verify(variation_key)
|
||||
def self.find_or_process_by!(blob_key:, encoded_variant_key:)
|
||||
new(ActiveStorage::Blob.find_by!(key: blob_key), variation: verifier.verify(encoded_variant_key)).processed
|
||||
end
|
||||
|
||||
def self.encode_key(variation)
|
||||
|
@ -25,8 +25,12 @@ class ActiveStorage::Variant
|
|||
@blob, @variation = blob, variation
|
||||
end
|
||||
|
||||
def processed
|
||||
process unless exist?
|
||||
self
|
||||
end
|
||||
|
||||
def url(expires_in: 5.minutes, disposition: :inline)
|
||||
perform unless exist?
|
||||
service.url blob_variant_key, expires_in: expires_in, disposition: disposition, filename: blob.filename
|
||||
end
|
||||
|
||||
|
@ -39,7 +43,7 @@ class ActiveStorage::Variant
|
|||
service.exist?(blob_variant_key)
|
||||
end
|
||||
|
||||
def perform
|
||||
def process
|
||||
upload_variant transform(download_blob)
|
||||
end
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@ class ActiveStorage::VariationTest < ActiveSupport::TestCase
|
|||
blob = ActiveStorage::Blob.create_after_upload! \
|
||||
io: File.open(File.expand_path("../fixtures/files/racecar.jpg", __FILE__)), filename: "racecar.jpg", content_type: "image/jpeg"
|
||||
|
||||
variant = blob.variant(resize: "100x100")
|
||||
|
||||
assert_match /racecar.jpg/, variant.url
|
||||
assert_match /racecar.jpg/, blob.variant(resize: "100x100").processed.url
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue