activestorage 5.2.8 → 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.

Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +102 -152
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +6 -5
  5. data/app/assets/javascripts/activestorage.js +4 -1
  6. data/app/controllers/active_storage/base_controller.rb +3 -5
  7. data/app/controllers/active_storage/blobs_controller.rb +1 -1
  8. data/app/controllers/active_storage/disk_controller.rb +4 -1
  9. data/app/controllers/active_storage/representations_controller.rb +1 -1
  10. data/app/controllers/concerns/active_storage/set_current.rb +15 -0
  11. data/app/javascript/activestorage/blob_record.js +6 -1
  12. data/app/jobs/active_storage/analyze_job.rb +4 -0
  13. data/app/jobs/active_storage/base_job.rb +0 -1
  14. data/app/jobs/active_storage/purge_job.rb +3 -0
  15. data/app/models/active_storage/attachment.rb +18 -9
  16. data/app/models/active_storage/blob/representable.rb +5 -5
  17. data/app/models/active_storage/blob.rb +63 -22
  18. data/app/models/active_storage/filename.rb +0 -6
  19. data/app/models/active_storage/preview.rb +3 -3
  20. data/app/models/active_storage/variant.rb +51 -52
  21. data/app/models/active_storage/variation.rb +23 -92
  22. data/config/routes.rb +13 -12
  23. data/db/update_migrate/20180723000244_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.rb +7 -0
  24. data/lib/active_storage/analyzer/video_analyzer.rb +2 -4
  25. data/lib/active_storage/analyzer.rb +9 -4
  26. data/lib/active_storage/attached/changes/create_many.rb +46 -0
  27. data/lib/active_storage/attached/changes/create_one.rb +68 -0
  28. data/lib/active_storage/attached/changes/create_one_of_many.rb +10 -0
  29. data/lib/active_storage/attached/changes/delete_many.rb +23 -0
  30. data/lib/active_storage/attached/changes/delete_one.rb +19 -0
  31. data/lib/active_storage/attached/changes.rb +16 -0
  32. data/lib/active_storage/attached/many.rb +16 -10
  33. data/lib/active_storage/attached/model.rb +140 -0
  34. data/lib/active_storage/attached/one.rb +16 -19
  35. data/lib/active_storage/attached.rb +7 -22
  36. data/lib/active_storage/downloader.rb +44 -0
  37. data/lib/active_storage/downloading.rb +8 -0
  38. data/lib/active_storage/engine.rb +36 -21
  39. data/lib/active_storage/errors.rb +22 -3
  40. data/lib/active_storage/gem_version.rb +4 -4
  41. data/lib/active_storage/previewer/poppler_pdf_previewer.rb +3 -3
  42. data/lib/active_storage/previewer/video_previewer.rb +2 -3
  43. data/lib/active_storage/previewer.rb +21 -11
  44. data/lib/active_storage/reflection.rb +64 -0
  45. data/lib/active_storage/service/azure_storage_service.rb +30 -14
  46. data/lib/active_storage/service/configurator.rb +3 -1
  47. data/lib/active_storage/service/disk_service.rb +20 -16
  48. data/lib/active_storage/service/gcs_service.rb +48 -46
  49. data/lib/active_storage/service/mirror_service.rb +1 -1
  50. data/lib/active_storage/service/s3_service.rb +10 -9
  51. data/lib/active_storage/service.rb +5 -6
  52. data/lib/active_storage/transformers/image_processing_transformer.rb +39 -0
  53. data/lib/active_storage/transformers/mini_magick_transformer.rb +38 -0
  54. data/lib/active_storage/transformers/transformer.rb +42 -0
  55. data/lib/active_storage.rb +13 -292
  56. data/lib/tasks/activestorage.rake +7 -0
  57. metadata +28 -16
  58. data/app/models/active_storage/filename/parameters.rb +0 -36
  59. 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