Class: Atreides::Photo

Inherits:
Base
  • Object
show all
Includes:
Extendable
Defined in:
app/models/atreides/photo.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#dom_id, #to_param

Class Method Details

.base_classObject



62
63
64
# File 'app/models/atreides/photo.rb', line 62

def base_class
  self
end

Instance Method Details

#add_to_queueObject



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_sizesObject



104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/models/atreides/photo.rb', line 104

def calculate_attachment_sizes
  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_featuresObject



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_imageObject



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_filesObject

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_modelsObject



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