Class: PhotoUploader

Inherits:
ApplicationUploader show all
Includes:
ImageDefaults
Defined in:
app/uploaders/photo_uploader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ImageDefaults

#extension_white_list

Methods inherited from ApplicationUploader

#store_dir

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



46
47
48
# File 'app/uploaders/photo_uploader.rb', line 46

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



46
47
48
# File 'app/uploaders/photo_uploader.rb', line 46

def width
  @width
end

Instance Method Details

#capture_size(file) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'app/uploaders/photo_uploader.rb', line 50

def capture_size(file)
  return unless version_name.blank?

  if file.path.nil?
    img = ::MiniMagick::Image.read(file.file)
    @width = img[:width]
    @height = img[:height]
  else
    @width, @height = `identify -format "%wx %h" #{file.path}`.split(/x/).map(&:to_i)
  end
end

#default_urlObject



6
7
8
# File 'app/uploaders/photo_uploader.rb', line 6

def default_url
  ActionController::Base.helpers.asset_path('images/default_photo.png')
end

#present?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/uploaders/photo_uploader.rb', line 19

def present?
  super && width.present? && height.present?
end

#urlObject



10
11
12
13
14
15
16
17
# File 'app/uploaders/photo_uploader.rb', line 10

def url
  if file.present? && File.exist?(file.file)
    file.file.match(%r{/system/uploads/.*}).to_s
  else
    default_url = '/assets/tramway/core/mona_lisa_from_prado_square.jpg'
    File.exist?(default_url) ? default_url : ''
  end
end