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_whitelist

Methods inherited from ApplicationUploader

#store_dir

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



27
28
29
# File 'app/uploaders/photo_uploader.rb', line 27

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



27
28
29
# File 'app/uploaders/photo_uploader.rb', line 27

def width
  @width
end

Instance Method Details

#capture_size(file) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'app/uploaders/photo_uploader.rb', line 31

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('mona_lisa_from_prado_square.png')
end

#medium_version_is_needed?(_new_file) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/uploaders/photo_uploader.rb', line 43

def medium_version_is_needed?(_new_file)
  version_is_needed? :medium
end

#small_version_is_needed?(_new_file) ⇒ Boolean

Returns:

  • (Boolean)


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

def small_version_is_needed?(_new_file)
  version_is_needed? :small
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

#version_is_needed?(version) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/uploaders/photo_uploader.rb', line 51

def version_is_needed?(version)
  model.class.photo_versions&.include? version
end