Class: S3Assets::Model
- Inherits:
-
Object
- Object
- S3Assets::Model
- Includes:
- Mongoid::Document, Mongoid::Timestamps::Created
- Defined in:
- lib/s3_assets/model.rb
Class Method Summary collapse
Instance Method Summary collapse
- #dj_priority ⇒ Object
- #download ⇒ Object
- #fetch_and_store_from_url! ⇒ Object
- #filename ⇒ Object
- #image? ⇒ Boolean
- #original_filename ⇒ Object
- #processable? ⇒ Boolean
- #processed? ⇒ Boolean
Class Method Details
.from_s3_params(bucket, key) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/s3_assets/model.rb', line 52 def self.from_s3_params(bucket, key) return nil if bucket.blank? || key.blank? key = URI.encode(key, "!@#$%^&*()+=[]{} ") url = "https://s3.amazonaws.com/#{bucket}/#{key}" self.new(absolute_url: url) end |
Instance Method Details
#dj_priority ⇒ Object
49 50 |
# File 'lib/s3_assets/model.rb', line 49 def dj_priority end |
#download ⇒ Object
25 26 27 |
# File 'lib/s3_assets/model.rb', line 25 def download ::S3Assets::Utility.download(self.asset.url) end |
#fetch_and_store_from_url! ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/s3_assets/model.rb', line 60 def fetch_and_store_from_url! return unless self.processable? begin self.remote_asset_url = self.absolute_url self.save! rescue CarrierWave::DownloadError => ex if ex..include?("Invalid Location URI") # "http://www.hiretale.com/files/resize_logo/13126logo original.png" # is not working without doing this due to redirect URL not encoded properly page = Mechanize.new.head(self.absolute_url) self.remote_asset_url = page.uri.to_s self.save! else raise ex end end end |
#filename ⇒ Object
42 43 44 45 46 47 |
# File 'lib/s3_assets/model.rb', line 42 def filename return nil if self.asset.url.blank? file_name = self.asset.url.split("?").first file_name = file_name.split("/").last file_name end |
#image? ⇒ Boolean
21 22 23 |
# File 'lib/s3_assets/model.rb', line 21 def image? self.content_type.to_s.downcase.include? "image" unless self.content_type.nil? end |
#original_filename ⇒ Object
29 30 31 32 |
# File 'lib/s3_assets/model.rb', line 29 def original_filename return nil if filename.blank? URI.unescape(filename) end |
#processable? ⇒ Boolean
34 35 36 |
# File 'lib/s3_assets/model.rb', line 34 def processable? self.absolute_url.present? && self.asset.blank? end |
#processed? ⇒ Boolean
38 39 40 |
# File 'lib/s3_assets/model.rb', line 38 def processed? !(processable?) end |