Class: Spree::Image

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

Instance Method Summary collapse

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Methods included from Preferences::Preferable

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

Instance Method Details

#filenameObject



33
34
35
# File 'app/models/spree/image.rb', line 33

def filename
  attachment_file_name
end

#find_dimensionsObject



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

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



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

def mini_url
  Spree::Deprecation.warn(
    'Spree::Image#mini_url is DEPRECATED. Use Spree::Image#url(:mini) instead.'
  )
  attachment.url(:mini, false)
end

#no_attachment_errorsObject

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



47
48
49
50
51
52
53
54
# File 'app/models/spree/image.rb', line 47

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

#url(size) ⇒ Object



29
30
31
# File 'app/models/spree/image.rb', line 29

def url(size)
  attachment.url(size)
end