Class: Attachment
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Attachment
- Includes:
- Dis::Model, PagesCore::Sweepable
- Defined in:
- app/models/attachment.rb
Instance Attribute Summary
Attributes included from PagesCore::Sweepable
Class Method Summary collapse
Instance Method Summary collapse
- #digest ⇒ Object
- #filename_extension ⇒ Object
- #filename_extension? ⇒ Boolean
- #format ⇒ Object
- #format? ⇒ Boolean
-
#to_param ⇒ Object
Includes a timestamp fingerprint in the URL param, so that rendered images can be cached indefinitely.
Class Method Details
.formats ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/attachment.rb', line 28 def formats { "audio/mpeg" => :mp3, "image/gif" => :gif, "image/jpeg" => :jpg, "image/jpg" => :jpg, "image/pjpeg" => :jpg, "image/png" => :png, "application/pdf" => :pdf } end |
.verifier ⇒ Object
22 23 24 25 26 |
# File 'app/models/attachment.rb', line 22 def verifier @verifier ||= PagesCore::DigestVerifier.new( Rails.application.key_generator.generate_key("attachments") ) end |
Instance Method Details
#digest ⇒ Object
41 42 43 44 45 |
# File 'app/models/attachment.rb', line 41 def digest return unless id self.class.verifier.generate(id.to_s) end |
#filename_extension ⇒ Object
55 56 57 58 59 60 61 |
# File 'app/models/attachment.rb', line 55 def filename_extension if filename_extension? filename.match(/\.([^.]+)$/)[1] else "" end end |
#filename_extension? ⇒ Boolean
63 64 65 |
# File 'app/models/attachment.rb', line 63 def filename_extension? filename.include?(".") end |
#format ⇒ Object
51 52 53 |
# File 'app/models/attachment.rb', line 51 def format self.class.formats[content_type] end |
#format? ⇒ Boolean
47 48 49 |
# File 'app/models/attachment.rb', line 47 def format? content_type && self.class.formats.key?(content_type) end |
#to_param ⇒ Object
Includes a timestamp fingerprint in the URL param, so that rendered images can be cached indefinitely.
69 70 71 |
# File 'app/models/attachment.rb', line 69 def to_param [id, updated_at.utc.to_fs()].join("-") end |