Class: PhotoUploader
- Inherits:
-
ApplicationUploader
- Object
- CarrierWave::Uploader::Base
- ApplicationUploader
- PhotoUploader
- Includes:
- ImageDefaults
- Defined in:
- app/uploaders/photo_uploader.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #capture_size(file) ⇒ Object
- #default_url ⇒ Object
- #medium_version_is_needed?(_new_file) ⇒ Boolean
- #small_version_is_needed?(_new_file) ⇒ Boolean
- #url ⇒ Object
- #version_is_needed?(version) ⇒ Boolean
Methods included from ImageDefaults
Methods inherited from ApplicationUploader
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
27 28 29 |
# File 'app/uploaders/photo_uploader.rb', line 27 def height @height end |
#width ⇒ Object (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_url ⇒ Object
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
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
47 48 49 |
# File 'app/uploaders/photo_uploader.rb', line 47 def small_version_is_needed?(_new_file) version_is_needed? :small end |
#url ⇒ Object
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
51 52 53 |
# File 'app/uploaders/photo_uploader.rb', line 51 def version_is_needed?(version) model.class.photo_versions&.include? version end |