Class: Atreides::Photo
- Includes:
- Extendable
- Defined in:
- app/models/atreides/photo.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_to_queue ⇒ Object
- #calculate_attachment_sizes ⇒ Object
- #clean_features ⇒ Object
- #fetch_remote_image ⇒ Object
-
#save_attached_files ⇒ Object
Overload Paperclip so that images are only resaved when it changes - uses too much memory otherwise.
- #size(thumb) ⇒ Object
- #update_associated_models ⇒ Object
Methods inherited from Base
Class Method Details
.base_class ⇒ Object
62 63 64 |
# File 'app/models/atreides/photo.rb', line 62 def base_class self end |
Instance Method Details
#add_to_queue ⇒ Object
80 81 82 83 |
# File 'app/models/atreides/photo.rb', line 80 def add_to_queue # Set the display order to be last self.display_order = Atreides::Photo.count(:conditions => {:photoable_id => self.photoable_id, :photoable_type => self.photoable_type}) end |
#calculate_attachment_sizes ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/models/atreides/photo.rb', line 104 def if (image_file_name?) self.sizes = {} self.image.queued_for_write.each {|key,file| self.sizes[key.to_sym]={} geo = Paperclip::Geometry.from_file(file.path) %w(width height).each{|dim| self.sizes[key.to_sym][dim.to_sym] = geo.send(dim.to_sym).to_i } } end end |
#clean_features ⇒ Object
38 39 40 41 42 43 |
# File 'app/models/atreides/photo.rb', line 38 def clean_features features.each do |f| f.photo = nil f.save end end |
#fetch_remote_image ⇒ Object
75 76 77 78 |
# File 'app/models/atreides/photo.rb', line 75 def fetch_remote_image # If there is a URL then download it and use self.image = do_download_remote_image if url_changed? end |
#save_attached_files ⇒ Object
Overload Paperclip so that images are only resaved when it changes - uses too much memory otherwise
98 99 100 |
# File 'app/models/atreides/photo.rb', line 98 def save_attached_files super if image_file_size_changed? end |
#size(thumb) ⇒ Object
90 91 92 93 94 95 |
# File 'app/models/atreides/photo.rb', line 90 def size(thumb) sizes[thumb.to_sym] rescue => exception logger.error { "Error getting image sizes: #{exception}" } {} end |
#update_associated_models ⇒ Object
85 86 87 88 |
# File 'app/models/atreides/photo.rb', line 85 def update_associated_models # Update assoc'd models features.update_all({:updated_at => Time.zone.now}) end |