Module: Alchemy::StorageAdapter::ActiveStorage
Defined Under Namespace
Modules: AttachmentClassMethods, PictureClassMethods
Classes: AttachmentUrl, PictureUrl, Preprocessor, SanitizeSvgJob
Instance Method Summary
collapse
Instance Method Details
#attachment_url_class ⇒ Object
30
31
32
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 30
def attachment_url_class
AttachmentUrl
end
|
85
86
87
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 85
def by_file_format_scope(file_format)
Picture.with_attached_image_file.joins(:image_file_blob).where(active_storage_blobs: {content_type: file_format})
end
|
#by_file_type_scope(file_type) ⇒ Alchemy::Atachment::ActiveRecord_Relation
91
92
93
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 91
def by_file_type_scope(file_type)
Attachment.with_attached_file.joins(:file_blob).where(active_storage_blobs: {content_type: file_type})
end
|
#file_extension(attachment) ⇒ String
115
116
117
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 115
def file_extension(attachment)
attachment.file&.filename&.extension
end
|
42
43
44
45
46
47
48
49
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 42
def file_formats(class_name, scope:)
attachment_scope = case class_name
when "Alchemy::Attachment" then scope.with_attached_file
when "Alchemy::Picture" then scope.with_attached_image_file
end
attachment_scope.pluck("active_storage_blobs.content_type").uniq.tap(&:compact!).presence || []
end
|
#file_mime_type(attachment) ⇒ String
109
110
111
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 109
def file_mime_type(attachment)
attachment.file&.content_type
end
|
#file_name(attachment) ⇒ String
97
98
99
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 97
def file_name(attachment)
attachment.file&.filename&.to_s
end
|
#file_size(attachment) ⇒ Integer
103
104
105
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 103
def file_size(attachment)
attachment.file&.byte_size
end
|
121
122
123
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 121
def has_convertible_format?(picture)
picture.image_file&.variable?
end
|
#image_file_extension(picture) ⇒ Integer
157
158
159
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 157
def image_file_extension(picture)
picture.image_file&.filename&.extension&.downcase
end
|
133
134
135
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 133
def image_file_format(picture)
picture.image_file&.content_type
end
|
#image_file_height(picture) ⇒ Integer
151
152
153
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 151
def image_file_height(picture)
picture.image_file&.metadata&.fetch(:height, nil)
end
|
#image_file_name(picture) ⇒ String
127
128
129
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 127
def image_file_name(picture)
picture.image_file&.filename&.to_s
end
|
#image_file_present?(picture) ⇒ TrueClass, FalseClass
163
164
165
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 163
def image_file_present?(picture)
picture.image_file.attached?
end
|
#image_file_size(picture) ⇒ Integer
139
140
141
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 139
def image_file_size(picture)
picture.image_file&.byte_size
end
|
#image_file_width(picture) ⇒ Integer
145
146
147
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 145
def image_file_width(picture)
picture.image_file&.metadata&.fetch(:width, nil)
end
|
#picture_url_class ⇒ Object
38
39
40
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 38
def picture_url_class
PictureUrl
end
|
#preloaded_pictures(pictures) ⇒ Object
Returns Alchemy::Picture::ActiveRecord_Relation.
169
170
171
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 169
def preloaded_pictures(pictures)
pictures.with_attached_image_file
end
|
#preprocessor_class ⇒ Object
34
35
36
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 34
def preprocessor_class
Preprocessor
end
|
#ransackable_associations(class_name) ⇒ Array<String>
70
71
72
73
74
75
76
77
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 70
def ransackable_associations(class_name)
case class_name
when "Alchemy::Attachment"
%w[file_blob]
when "Alchemy::Picture"
%w[image_file_blob]
end
end
|
#ransackable_attributes(_class_name) ⇒ Array<String>
64
65
66
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 64
def ransackable_attributes(_class_name)
%w[name]
end
|
#rescuable_errors ⇒ Object
79
80
81
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 79
def rescuable_errors
::ActiveStorage::Error
end
|
#searchable_alchemy_resource_attributes(class_name) ⇒ Array<String>
53
54
55
56
57
58
59
60
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 53
def searchable_alchemy_resource_attributes(class_name)
case class_name
when "Alchemy::Attachment"
%w[name file_blob_filename]
when "Alchemy::Picture"
%w[name image_file_blob_filename]
end
end
|
#set_attachment_name?(attachment) ⇒ TrueClass, FalseClass
175
176
177
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 175
def set_attachment_name?(attachment)
attachment.file.changed?
end
|