Class: Caboose::ProductImage

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/caboose/product_image.rb

Instance Method Summary collapse

Instance Method Details

#as_json(options = {}) ⇒ Object


63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/caboose/product_image.rb', line 63

def as_json(options={})
  self.attributes.merge({
    :urls => {
      :tiny => self.url(:tiny),
      :thumb => self.url(:thumb),
      :medium => self.url(:medium),
      :large => self.url(:large),
      :huge => self.url(:huge)
    }
  })
end

#processObject


40
41
42
43
44
45
46
# File 'app/models/caboose/product_image.rb', line 40

def process
  config = AssetSync.config
  bucket = config.fog_directory
  uri = "http://#{bucket}.s3.amazonaws.com/media-images/#{self.id}#{File.extname(self.title.downcase)}"
  self.image = URI.parse(uri)
  self.save
end

#url(size) ⇒ Object

'tiny', 'thumb', 'medium', 'large', 'huge'


48
49
50
51
# File 'app/models/caboose/product_image.rb', line 48

def url(size) # 'tiny', 'thumb', 'medium', 'large', 'huge'
  return self.media.image.url(size) if self.media
  return self.image.url(size)
end

#urlsObject


53
54
55
56
57
58
59
60
61
# File 'app/models/caboose/product_image.rb', line 53

def urls
  {
    :tiny   => self.url(:tiny),
    :thumb  => self.url(:thumb),
    :medium => self.url(:medium),
    :large  => self.url(:large),
    :huge   => self.url(:huge)
  }      
end