Module: Alchemy::StorageAdapter::ActiveStorage
Defined Under Namespace
Modules: AttachmentClassMethods, PictureClassMethods
Classes: AttachmentUrl, PictureUrl, Preprocessor
Instance Method Summary
collapse
Instance Method Details
#attachment_url_class ⇒ Object
23
24
25
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 23
def attachment_url_class
AttachmentUrl
end
|
78
79
80
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 78
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
84
85
86
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 84
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
108
109
110
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 108
def file_extension(attachment)
attachment.file&.filename&.extension
end
|
35
36
37
38
39
40
41
42
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 35
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
102
103
104
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 102
def file_mime_type(attachment)
attachment.file&.content_type
end
|
#file_name(attachment) ⇒ String
90
91
92
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 90
def file_name(attachment)
attachment.file&.filename&.to_s
end
|
#file_size(attachment) ⇒ Integer
96
97
98
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 96
def file_size(attachment)
attachment.file&.byte_size
end
|
114
115
116
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 114
def has_convertible_format?(picture)
picture.image_file&.variable?
end
|
#image_file_extension(picture) ⇒ Integer
150
151
152
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 150
def image_file_extension(picture)
picture.image_file&.filename&.extension&.downcase
end
|
126
127
128
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 126
def image_file_format(picture)
picture.image_file&.content_type
end
|
#image_file_height(picture) ⇒ Integer
144
145
146
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 144
def image_file_height(picture)
picture.image_file&.metadata&.fetch(:height, nil)
end
|
#image_file_name(picture) ⇒ String
120
121
122
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 120
def image_file_name(picture)
picture.image_file&.filename&.to_s
end
|
#image_file_present?(picture) ⇒ TrueClass, FalseClass
156
157
158
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 156
def image_file_present?(picture)
picture.image_file.attached?
end
|
#image_file_size(picture) ⇒ Integer
132
133
134
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 132
def image_file_size(picture)
picture.image_file&.byte_size
end
|
#image_file_width(picture) ⇒ Integer
138
139
140
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 138
def image_file_width(picture)
picture.image_file&.metadata&.fetch(:width, nil)
end
|
#picture_url_class ⇒ Object
31
32
33
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 31
def picture_url_class
PictureUrl
end
|
#preloaded_pictures(pictures) ⇒ Object
Returns Alchemy::Picture::ActiveRecord_Relation.
162
163
164
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 162
def preloaded_pictures(pictures)
pictures.with_attached_image_file
end
|
#preprocessor_class ⇒ Object
27
28
29
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 27
def preprocessor_class
Preprocessor
end
|
#ransackable_associations(class_name) ⇒ Array<String>
63
64
65
66
67
68
69
70
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 63
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>
57
58
59
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 57
def ransackable_attributes(_class_name)
%w[name]
end
|
#rescuable_errors ⇒ Object
72
73
74
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 72
def rescuable_errors
::ActiveStorage::Error
end
|
#searchable_alchemy_resource_attributes(class_name) ⇒ Array<String>
46
47
48
49
50
51
52
53
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 46
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
168
169
170
|
# File 'app/models/alchemy/storage_adapter/active_storage.rb', line 168
def set_attachment_name?(attachment)
attachment.file.changed?
end
|