Class: Asset
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Asset
- Defined in:
- lib/sga/asset.rb
Instance Method Summary collapse
- #browser_safe? ⇒ Boolean (also: #web_safe?)
- #content_type ⇒ Object
- #detach(attached) ⇒ Object
- #file_md5sum ⇒ Object
-
#icon ⇒ Object
This method assumes you have images that corespond to the filetypes.
- #name ⇒ Object
- #path ⇒ Object
-
#replace_style(style, file) ⇒ Object
This method will replace one of the existing thumbnails with an file provided.
- #url(*args) ⇒ Object
- #url_without_random(format = :original) ⇒ Object
Instance Method Details
#browser_safe? ⇒ Boolean Also known as: web_safe?
33 34 35 |
# File 'lib/sga/asset.rb', line 33 def browser_safe? %w(jpg gif png).include?(url.split('.').last.sub(/\?.+/, "").downcase) end |
#content_type ⇒ Object
29 30 31 |
# File 'lib/sga/asset.rb', line 29 def content_type data_content_type end |
#detach(attached) ⇒ Object
53 54 55 56 57 |
# File 'lib/sga/asset.rb', line 53 def detach(attached) a = attachings.find(:first, :conditions => ["attachable_id = ? AND attachable_type = ?", attached, attached.class.to_s]) raise ActiveRecord::RecordNotFound unless a a.destroy end |
#file_md5sum ⇒ Object
63 64 65 |
# File 'lib/sga/asset.rb', line 63 def file_md5sum IO.popen("md5sum '#{path}' | awk '{print $1}'"){|f| f.gets.strip} end |
#icon ⇒ Object
This method assumes you have images that corespond to the filetypes. For example “image/png” becomes “image-png.png”
49 50 51 |
# File 'lib/sga/asset.rb', line 49 def icon "#{data_content_type.gsub(/[\/\.]/,'-')}.png" end |
#name ⇒ Object
25 26 27 |
# File 'lib/sga/asset.rb', line 25 def name data_file_name end |
#path ⇒ Object
59 60 61 |
# File 'lib/sga/asset.rb', line 59 def path File.join RAILS_ROOT, 'public', self.url_without_random end |
#replace_style(style, file) ⇒ Object
This method will replace one of the existing thumbnails with an file provided.
39 40 41 42 43 44 45 |
# File 'lib/sga/asset.rb', line 39 def replace_style(style, file) style = style.downcase.to_sym if data.styles.keys.include?(style) if File.exist?(RAILS_ROOT + '/public' + a.data(style)) end end end |
#url(*args) ⇒ Object
21 22 23 |
# File 'lib/sga/asset.rb', line 21 def url(*args) data.url(*args) end |
#url_without_random(format = :original) ⇒ Object
67 68 69 |
# File 'lib/sga/asset.rb', line 67 def url_without_random format=:original self.url(format) =~ /^(.*)\?\d*$/ ? $1 : self.url(format) end |