Class: Alchemy::Attachment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Alchemy::Attachment
- Includes:
- Filetypes, NameConversions, Touching
- Defined in:
- app/models/alchemy/attachment.rb
Constant Summary
Constants included from Filetypes
Filetypes::ARCHIVE_FILE_TYPES, Filetypes::AUDIO_FILE_TYPES, Filetypes::IMAGE_FILE_TYPES, Filetypes::VCARD_FILE_TYPES, Filetypes::VIDEO_FILE_TYPES
Class Method Summary collapse
Instance Method Summary collapse
- #extension ⇒ Object (also: #suffix)
-
#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.
- #sanitized_filename ⇒ Object
-
#to_jq_upload ⇒ Object
Instance methods.
- #urlname ⇒ Object
Methods included from Touching
Methods included from NameConversions
#convert_to_humanized_name, #convert_to_urlname
Class Method Details
.find_paginated(params, per_page, order) ⇒ Object
57 58 59 60 61 |
# File 'app/models/alchemy/attachment.rb', line 57 def find_paginated(params, per_page, order) = Attachment.arel_table cond = [:name].matches("%#{params[:query]}%").or([:file_name].matches("%#{params[:query]}%")) self.where(cond).page(params[:page] || 1).per(per_page).order(order) end |
Instance Method Details
#extension ⇒ Object Also known as: suffix
84 85 86 |
# File 'app/models/alchemy/attachment.rb', line 84 def extension file_name.split(".").last end |
#icon_css_class ⇒ Object
Returns a css class name for kind of file
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'app/models/alchemy/attachment.rb', line 91 def icon_css_class case file_mime_type when *ARCHIVE_FILE_TYPES then "archive" when *AUDIO_FILE_TYPES then "audio" when *IMAGE_FILE_TYPES then "image" when *VIDEO_FILE_TYPES then "video" when "application/x-shockwave-flash" then "flash" when "image/x-psd" then "psd" when "text/plain" then "text" when "application/rtf" then "rtf" when "application/pdf" then "pdf" when "application/msword" then "word" when "application/vnd.ms-excel" then "excel" when *VCARD_FILE_TYPES then "vcard" else "file" end end |
#restricted? ⇒ Boolean
Checks if the attachment is restricted, because it is attached on restricted pages only
80 81 82 |
# File 'app/models/alchemy/attachment.rb', line 80 def restricted? pages.any? && pages.not_restricted.blank? end |
#sanitized_filename ⇒ Object
121 122 123 124 125 126 |
# File 'app/models/alchemy/attachment.rb', line 121 def sanitized_filename parts = self.file_name.split('.') sfx = parts.pop name = convert_to_urlname(parts.join('-')) "#{name}.#{sfx}" end |
#to_jq_upload ⇒ Object
Instance methods
67 68 69 70 71 72 73 |
# File 'app/models/alchemy/attachment.rb', line 67 def to_jq_upload { "name" => read_attribute(:file_name), "size" => read_attribute(:file_size), 'error' => errors[:file].join } end |
#urlname ⇒ Object
75 76 77 |
# File 'app/models/alchemy/attachment.rb', line 75 def urlname read_attribute :file_name end |