Class: Alchemy::Attachment
- Inherits:
-
BaseRecord
- Object
- ActiveRecord::Base
- BaseRecord
- Alchemy::Attachment
- Includes:
- Filetypes, NameConversions, RelatableResource, Taggable, TouchElements
- Defined in:
- app/models/alchemy/attachment.rb
Constant Summary
Constants included from Filetypes
Filetypes::ARCHIVE_FILE_TYPES, Filetypes::AUDIO_FILE_TYPES, Filetypes::EXCEL_FILE_TYPES, Filetypes::IMAGE_FILE_TYPES, Filetypes::POWERPOINT_FILE_TYPES, Filetypes::TEXT_FILE_TYPES, Filetypes::VCARD_FILE_TYPES, Filetypes::VIDEO_FILE_TYPES, Filetypes::WORD_FILE_TYPES
Constants included from SearchableResource
SearchableResource::SEARCHABLE_COLUMN_TYPES
Class Method Summary collapse
- .allowed_filetypes ⇒ Object
- .file_types(scope = all) ⇒ Object
- .last_upload ⇒ Object
- .ransackable_associations(_auth_object = nil) ⇒ Object
- .ransackable_attributes(_auth_object = nil) ⇒ Object
- .ransackable_scopes(_auth_object = nil) ⇒ Object
- .searchable_alchemy_resource_attributes ⇒ Object
-
.url_class ⇒ Object
The class used to generate URLs for attachments.
-
.url_class=(klass) ⇒ Object
Set a different attachment url class.
Instance Method Summary collapse
-
#extension ⇒ Object
(also: #suffix)
File format suffix.
- #file_mime_type ⇒ Object
-
#file_name ⇒ Object
File name.
-
#file_size ⇒ Object
File size.
-
#icon_css_class ⇒ Object
Returns a css class name for kind of file.
-
#restricted? ⇒ Boolean
Checks if the attachment is restricted, because it is attached on restricted pages only.
-
#slug ⇒ Object
An url save filename without format suffix.
-
#url(options = {}) ⇒ Object
Instance methods.
Methods included from RelatableResource
Methods included from TouchElements
Methods included from Taggable
Methods included from NameConversions
#convert_to_humanized_name, #convert_to_urlname
Methods included from ConfigMissing
Methods included from SearchableResource
#ransackable_associations, #ransackable_attributes, #ransackable_scopes, #ransortable_attributes
Class Method Details
.allowed_filetypes ⇒ Object
77 78 79 |
# File 'app/models/alchemy/attachment.rb', line 77 def allowed_filetypes Alchemy.config.uploader.allowed_filetypes. end |
.file_types(scope = all) ⇒ Object
73 74 75 |
# File 'app/models/alchemy/attachment.rb', line 73 def file_types(scope = all) Alchemy.storage_adapter.file_formats(name, scope:) end |
.last_upload ⇒ Object
54 55 56 57 58 59 |
# File 'app/models/alchemy/attachment.rb', line 54 def last_upload last_id = Attachment.maximum(:id) return Attachment.all unless last_id where(id: last_id) end |
.ransackable_associations(_auth_object = nil) ⇒ Object
69 70 71 |
# File 'app/models/alchemy/attachment.rb', line 69 def ransackable_associations(_auth_object = nil) Alchemy.storage_adapter.ransackable_associations(name) end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
65 66 67 |
# File 'app/models/alchemy/attachment.rb', line 65 def ransackable_attributes(_auth_object = nil) Alchemy.storage_adapter.ransackable_attributes(name) end |
.ransackable_scopes(_auth_object = nil) ⇒ Object
81 82 83 |
# File 'app/models/alchemy/attachment.rb', line 81 def ransackable_scopes(_auth_object = nil) %i[by_file_type recent last_upload without_tag deletable] end |
.searchable_alchemy_resource_attributes ⇒ Object
61 62 63 |
# File 'app/models/alchemy/attachment.rb', line 61 def searchable_alchemy_resource_attributes Alchemy.storage_adapter.searchable_alchemy_resource_attributes(name) end |
.url_class ⇒ Object
The class used to generate URLs for attachments
43 44 45 |
# File 'app/models/alchemy/attachment.rb', line 43 def url_class @_url_class ||= Alchemy.storage_adapter. end |
.url_class=(klass) ⇒ Object
Set a different attachment url class
50 51 52 |
# File 'app/models/alchemy/attachment.rb', line 50 def url_class=(klass) @_url_class = klass end |
Instance Method Details
#extension ⇒ Object Also known as: suffix
File format suffix
126 127 128 |
# File 'app/models/alchemy/attachment.rb', line 126 def extension Alchemy.storage_adapter.file_extension(self) end |
#file_mime_type ⇒ Object
121 122 123 |
# File 'app/models/alchemy/attachment.rb', line 121 def file_mime_type Alchemy.storage_adapter.file_mime_type(self) end |
#file_name ⇒ Object
File name
112 113 114 |
# File 'app/models/alchemy/attachment.rb', line 112 def file_name Alchemy.storage_adapter.file_name(self) end |
#file_size ⇒ Object
File size
117 118 119 |
# File 'app/models/alchemy/attachment.rb', line 117 def file_size Alchemy.storage_adapter.file_size(self) end |
#icon_css_class ⇒ Object
Returns a css class name for kind of file
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'app/models/alchemy/attachment.rb', line 134 def icon_css_class case file_mime_type when "application/pdf" "file-pdf-2" when *TEXT_FILE_TYPES "file-text" when *EXCEL_FILE_TYPES "file-excel-2" when *POWERPOINT_FILE_TYPES "file-ppt-2" when *WORD_FILE_TYPES "file-word-2" when *VCARD_FILE_TYPES "profile" when *ARCHIVE_FILE_TYPES "file-zip" when *AUDIO_FILE_TYPES "file-music" when *IMAGE_FILE_TYPES "file-image" when *VIDEO_FILE_TYPES "file-video" else "file-3" end end |
#restricted? ⇒ Boolean
Checks if the attachment is restricted, because it is attached on restricted pages only
107 108 109 |
# File 'app/models/alchemy/attachment.rb', line 107 def restricted? pages.any? && pages.not_restricted.blank? end |
#slug ⇒ Object
An url save filename without format suffix
102 103 104 |
# File 'app/models/alchemy/attachment.rb', line 102 def slug CGI.escape(file_name.gsub(/\.#{extension}$/, "").tr(".", " ")) end |
#url(options = {}) ⇒ Object
Instance methods
97 98 99 |
# File 'app/models/alchemy/attachment.rb', line 97 def url( = {}) self.class.url_class.new(self).call() end |