activestorage 5.2.8.1 → 6.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activestorage might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +102 -157
- data/MIT-LICENSE +1 -1
- data/README.md +6 -5
- data/app/assets/javascripts/activestorage.js +4 -1
- data/app/controllers/active_storage/base_controller.rb +3 -5
- data/app/controllers/active_storage/blobs_controller.rb +1 -1
- data/app/controllers/active_storage/disk_controller.rb +4 -1
- data/app/controllers/active_storage/representations_controller.rb +1 -1
- data/app/controllers/concerns/active_storage/set_current.rb +15 -0
- data/app/javascript/activestorage/blob_record.js +6 -1
- data/app/jobs/active_storage/analyze_job.rb +4 -0
- data/app/jobs/active_storage/base_job.rb +0 -1
- data/app/jobs/active_storage/purge_job.rb +3 -0
- data/app/models/active_storage/attachment.rb +18 -9
- data/app/models/active_storage/blob/representable.rb +5 -5
- data/app/models/active_storage/blob.rb +63 -22
- data/app/models/active_storage/filename.rb +0 -6
- data/app/models/active_storage/preview.rb +3 -3
- data/app/models/active_storage/variant.rb +51 -52
- data/app/models/active_storage/variation.rb +23 -92
- data/config/routes.rb +13 -12
- data/db/update_migrate/20180723000244_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.rb +7 -0
- data/lib/active_storage/analyzer/video_analyzer.rb +2 -4
- data/lib/active_storage/analyzer.rb +9 -4
- data/lib/active_storage/attached/changes/create_many.rb +46 -0
- data/lib/active_storage/attached/changes/create_one.rb +68 -0
- data/lib/active_storage/attached/changes/create_one_of_many.rb +10 -0
- data/lib/active_storage/attached/changes/delete_many.rb +23 -0
- data/lib/active_storage/attached/changes/delete_one.rb +19 -0
- data/lib/active_storage/attached/changes.rb +16 -0
- data/lib/active_storage/attached/many.rb +16 -10
- data/lib/active_storage/attached/model.rb +140 -0
- data/lib/active_storage/attached/one.rb +16 -19
- data/lib/active_storage/attached.rb +7 -22
- data/lib/active_storage/downloader.rb +44 -0
- data/lib/active_storage/downloading.rb +8 -0
- data/lib/active_storage/engine.rb +36 -21
- data/lib/active_storage/errors.rb +22 -3
- data/lib/active_storage/gem_version.rb +4 -4
- data/lib/active_storage/previewer/poppler_pdf_previewer.rb +3 -3
- data/lib/active_storage/previewer/video_previewer.rb +2 -3
- data/lib/active_storage/previewer.rb +21 -11
- data/lib/active_storage/reflection.rb +64 -0
- data/lib/active_storage/service/azure_storage_service.rb +30 -14
- data/lib/active_storage/service/configurator.rb +3 -1
- data/lib/active_storage/service/disk_service.rb +20 -16
- data/lib/active_storage/service/gcs_service.rb +48 -46
- data/lib/active_storage/service/mirror_service.rb +1 -1
- data/lib/active_storage/service/s3_service.rb +10 -9
- data/lib/active_storage/service.rb +5 -6
- data/lib/active_storage/transformers/image_processing_transformer.rb +39 -0
- data/lib/active_storage/transformers/mini_magick_transformer.rb +38 -0
- data/lib/active_storage/transformers/transformer.rb +42 -0
- data/lib/active_storage.rb +13 -292
- data/lib/tasks/activestorage.rake +7 -0
- metadata +31 -19
- data/app/models/active_storage/filename/parameters.rb +0 -36
- data/lib/active_storage/attached/macros.rb +0 -110
@@ -1,110 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveStorage
|
4
|
-
# Provides the class-level DSL for declaring that an Active Record model has attached blobs.
|
5
|
-
module Attached::Macros
|
6
|
-
# Specifies the relation between a single attachment and the model.
|
7
|
-
#
|
8
|
-
# class User < ActiveRecord::Base
|
9
|
-
# has_one_attached :avatar
|
10
|
-
# end
|
11
|
-
#
|
12
|
-
# There is no column defined on the model side, Active Storage takes
|
13
|
-
# care of the mapping between your records and the attachment.
|
14
|
-
#
|
15
|
-
# To avoid N+1 queries, you can include the attached blobs in your query like so:
|
16
|
-
#
|
17
|
-
# User.with_attached_avatar
|
18
|
-
#
|
19
|
-
# Under the covers, this relationship is implemented as a +has_one+ association to a
|
20
|
-
# ActiveStorage::Attachment record and a +has_one-through+ association to a
|
21
|
-
# ActiveStorage::Blob record. These associations are available as +avatar_attachment+
|
22
|
-
# and +avatar_blob+. But you shouldn't need to work with these associations directly in
|
23
|
-
# most circumstances.
|
24
|
-
#
|
25
|
-
# The system has been designed to having you go through the ActiveStorage::Attached::One
|
26
|
-
# proxy that provides the dynamic proxy to the associations and factory methods, like +attach+.
|
27
|
-
#
|
28
|
-
# If the +:dependent+ option isn't set, the attachment will be purged
|
29
|
-
# (i.e. destroyed) whenever the record is destroyed.
|
30
|
-
def has_one_attached(name, dependent: :purge_later)
|
31
|
-
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
32
|
-
def #{name}
|
33
|
-
@active_storage_attached_#{name} ||= ActiveStorage::Attached::One.new("#{name}", self, dependent: #{dependent == :purge_later ? ":purge_later" : "false"})
|
34
|
-
end
|
35
|
-
|
36
|
-
def #{name}=(attachable)
|
37
|
-
#{name}.attach(attachable)
|
38
|
-
end
|
39
|
-
CODE
|
40
|
-
|
41
|
-
has_one :"#{name}_attachment", -> { where(name: name) }, class_name: "ActiveStorage::Attachment", as: :record, inverse_of: :record, dependent: false
|
42
|
-
has_one :"#{name}_blob", through: :"#{name}_attachment", class_name: "ActiveStorage::Blob", source: :blob
|
43
|
-
|
44
|
-
scope :"with_attached_#{name}", -> { includes("#{name}_attachment": :blob) }
|
45
|
-
|
46
|
-
if dependent == :purge_later
|
47
|
-
after_destroy_commit { public_send(name).purge_later }
|
48
|
-
else
|
49
|
-
before_destroy { public_send(name).detach }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# Specifies the relation between multiple attachments and the model.
|
54
|
-
#
|
55
|
-
# class Gallery < ActiveRecord::Base
|
56
|
-
# has_many_attached :photos
|
57
|
-
# end
|
58
|
-
#
|
59
|
-
# There are no columns defined on the model side, Active Storage takes
|
60
|
-
# care of the mapping between your records and the attachments.
|
61
|
-
#
|
62
|
-
# To avoid N+1 queries, you can include the attached blobs in your query like so:
|
63
|
-
#
|
64
|
-
# Gallery.where(user: Current.user).with_attached_photos
|
65
|
-
#
|
66
|
-
# Under the covers, this relationship is implemented as a +has_many+ association to a
|
67
|
-
# ActiveStorage::Attachment record and a +has_many-through+ association to a
|
68
|
-
# ActiveStorage::Blob record. These associations are available as +photos_attachments+
|
69
|
-
# and +photos_blobs+. But you shouldn't need to work with these associations directly in
|
70
|
-
# most circumstances.
|
71
|
-
#
|
72
|
-
# The system has been designed to having you go through the ActiveStorage::Attached::Many
|
73
|
-
# proxy that provides the dynamic proxy to the associations and factory methods, like +#attach+.
|
74
|
-
#
|
75
|
-
# If the +:dependent+ option isn't set, all the attachments will be purged
|
76
|
-
# (i.e. destroyed) whenever the record is destroyed.
|
77
|
-
def has_many_attached(name, dependent: :purge_later)
|
78
|
-
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
79
|
-
def #{name}
|
80
|
-
@active_storage_attached_#{name} ||= ActiveStorage::Attached::Many.new("#{name}", self, dependent: #{dependent == :purge_later ? ":purge_later" : "false"})
|
81
|
-
end
|
82
|
-
|
83
|
-
def #{name}=(attachables)
|
84
|
-
#{name}.attach(attachables)
|
85
|
-
end
|
86
|
-
CODE
|
87
|
-
|
88
|
-
has_many :"#{name}_attachments", -> { where(name: name) }, as: :record, class_name: "ActiveStorage::Attachment", inverse_of: :record, dependent: false do
|
89
|
-
def purge
|
90
|
-
each(&:purge)
|
91
|
-
reset
|
92
|
-
end
|
93
|
-
|
94
|
-
def purge_later
|
95
|
-
each(&:purge_later)
|
96
|
-
reset
|
97
|
-
end
|
98
|
-
end
|
99
|
-
has_many :"#{name}_blobs", through: :"#{name}_attachments", class_name: "ActiveStorage::Blob", source: :blob
|
100
|
-
|
101
|
-
scope :"with_attached_#{name}", -> { includes("#{name}_attachments": :blob) }
|
102
|
-
|
103
|
-
if dependent == :purge_later
|
104
|
-
after_destroy_commit { public_send(name).purge_later }
|
105
|
-
else
|
106
|
-
before_destroy { public_send(name).detach }
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|