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
28
29
30
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 28
def attachment_url_class
AttachmentUrl
end
|
83
84
85
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 83
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
89
90
91
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 89
def by_file_type_scope(file_type)
Attachment.with_attached_file.joins(:file_blob).where(active_storage_blobs: {content_type: file_type})
end
|
#file_basename(attachment) ⇒ String
101
102
103
104
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 101
def file_basename(attachment)
filename = attachment.file&.filename.to_s
File.basename(filename, File.extname(filename))
end
|
#file_extension(attachment) ⇒ String
126
127
128
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 126
def file_extension(attachment)
attachment.file&.filename&.extension
end
|
40
41
42
43
44
45
46
47
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 40
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
120
121
122
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 120
def file_mime_type(attachment)
attachment.file&.content_type
end
|
#file_name(attachment) ⇒ String
108
109
110
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 108
def file_name(attachment)
attachment.file&.filename&.to_s
end
|
#file_size(attachment) ⇒ Integer
114
115
116
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 114
def file_size(attachment)
attachment.file&.byte_size
end
|
132
133
134
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 132
def has_convertible_format?(picture)
picture.image_file&.variable?
end
|
#image_file_basename(picture) ⇒ String
138
139
140
141
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 138
def image_file_basename(picture)
filename = picture.image_file&.filename.to_s
File.basename(filename, File.extname(filename))
end
|
#image_file_extension(picture) ⇒ Integer
175
176
177
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 175
def image_file_extension(picture)
picture.image_file&.filename&.extension&.downcase
end
|
151
152
153
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 151
def image_file_format(picture)
picture.image_file&.content_type
end
|
#image_file_height(picture) ⇒ Integer
169
170
171
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 169
def image_file_height(picture)
picture.image_file&.metadata&.fetch(:height, nil)
end
|
#image_file_name(picture) ⇒ String
145
146
147
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 145
def image_file_name(picture)
picture.image_file&.filename&.to_s
end
|
#image_file_present?(picture) ⇒ TrueClass, FalseClass
181
182
183
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 181
def image_file_present?(picture)
picture.image_file.attached?
end
|
#image_file_size(picture) ⇒ Integer
157
158
159
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 157
def image_file_size(picture)
picture.image_file&.byte_size
end
|
#image_file_width(picture) ⇒ Integer
163
164
165
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 163
def image_file_width(picture)
picture.image_file&.metadata&.fetch(:width, nil)
end
|
#not_file_type_scope(file_type) ⇒ Alchemy::Atachment::ActiveRecord_Relation
95
96
97
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 95
def not_file_type_scope(file_type)
Attachment.with_attached_file.joins(:file_blob).where.not(active_storage_blobs: {content_type: file_type})
end
|
#picture_url_class ⇒ Object
36
37
38
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 36
def picture_url_class
PictureUrl
end
|
#preloaded_pictures(pictures) ⇒ Object
Returns Alchemy::Picture::ActiveRecord_Relation.
187
188
189
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 187
def preloaded_pictures(pictures)
pictures.with_attached_image_file
end
|
#preprocessor_class ⇒ Object
32
33
34
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 32
def preprocessor_class
Preprocessor
end
|
#ransackable_associations(class_name) ⇒ Array<String>
68
69
70
71
72
73
74
75
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 68
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>
62
63
64
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 62
def ransackable_attributes(_class_name)
%w[name]
end
|
#rescuable_errors ⇒ Object
77
78
79
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 77
def rescuable_errors
::ActiveStorage::Error
end
|
#searchable_alchemy_resource_attributes(class_name) ⇒ Array<String>
51
52
53
54
55
56
57
58
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 51
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
193
194
195
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 193
def set_attachment_name?(attachment)
attachment.file.changed?
end
|