Class: Spree::Image

Inherits:
Asset
  • Object
show all
Defined in:
app/models/spree/image.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

belongs_to_required_by_default, page, spree_base_scopes

Methods included from Preferences::Preferable

#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Class Method Details

.accepted_image_typesObject


5
6
7
# File 'app/models/spree/image.rb', line 5

def self.accepted_image_types
  %w(image/jpeg image/jpg image/png image/gif)
end

Instance Method Details

#find_dimensionsObject


28
29
30
31
32
33
34
35
# File 'app/models/spree/image.rb', line 28

def find_dimensions
  temporary = attachment.queued_for_write[:original]
  filename = temporary.path unless temporary.nil?
  filename = attachment.path if filename.blank?
  geometry = Paperclip::Geometry.from_file(filename)
  self.attachment_width  = geometry.width
  self.attachment_height = geometry.height
end

#mini_urlObject

used by admin products autocomplete


24
25
26
# File 'app/models/spree/image.rb', line 24

def mini_url
  attachment.url(:mini, false)
end

#no_attachment_errorsObject

if there are errors from the plugin, then add a more meaningful message


38
39
40
41
42
43
44
45
# File 'app/models/spree/image.rb', line 38

def no_attachment_errors
  unless attachment.errors.empty?
    # uncomment this to get rid of the less-than-useful interim messages
    # errors.clear
    errors.add :attachment, "Paperclip returned errors for file '#{attachment_file_name}' - check ImageMagick installation or image source file."
    false
  end
end