Class: PaperclipUpload::Upload
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- PaperclipUpload::Upload
- Defined in:
- app/models/paperclip_upload/upload.rb
Constant Summary collapse
- IDENTIFIER_LENGTH =
8
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.find_by_identifier(_identifier) ⇒ Object
40 41 42 43 |
# File 'app/models/paperclip_upload/upload.rb', line 40 def self.find_by_identifier(_identifier) decoded_id = identifier_to_id(_identifier) PaperclipUpload::Upload.find(decoded_id) end |
.hashid ⇒ Object
49 50 51 |
# File 'app/models/paperclip_upload/upload.rb', line 49 def self.hashid Hashids.new(PaperclipUpload.hash_salt, IDENTIFIER_LENGTH) end |
.identifier_to_id(_identifier) ⇒ Object
53 54 55 |
# File 'app/models/paperclip_upload/upload.rb', line 53 def self.identifier_to_id(_identifier) hashid.decode(_identifier).first end |
Instance Method Details
#download_url ⇒ Object
45 46 47 |
# File 'app/models/paperclip_upload/upload.rb', line 45 def download_url file.url end |
#file_extension ⇒ Object
30 31 32 33 |
# File 'app/models/paperclip_upload/upload.rb', line 30 def file_extension return unless file.exists? File.extname(file.original_filename).split('.').last end |
#file_name ⇒ Object
35 36 37 38 |
# File 'app/models/paperclip_upload/upload.rb', line 35 def file_name return unless file.exists? file_file_name.gsub(".#{file_extension}", "") end |
#identifier ⇒ Object
25 26 27 28 |
# File 'app/models/paperclip_upload/upload.rb', line 25 def identifier raise "valid with saved instance only" if id.blank? self.class.hashid.encode(id) end |