Class: ActiveStorageValidations::Metadata
- Inherits:
-
Object
- Object
- ActiveStorageValidations::Metadata
- Includes:
- ASVLoggable
- Defined in:
- lib/active_storage_validations/metadata.rb
Defined Under Namespace
Classes: InvalidImageError
Constant Summary collapse
- DEFAULT_IMAGE_PROCESSOR =
:mini_magick.freeze
Instance Attribute Summary collapse
-
#attachable ⇒ Object
readonly
Returns the value of attribute attachable.
Instance Method Summary collapse
-
#initialize(attachable) ⇒ Metadata
constructor
A new instance of Metadata.
- #metadata ⇒ Object
- #valid? ⇒ Boolean
Methods included from ASVLoggable
Constructor Details
#initialize(attachable) ⇒ Metadata
Returns a new instance of Metadata.
15 16 17 18 |
# File 'lib/active_storage_validations/metadata.rb', line 15 def initialize(attachable) require_image_processor @attachable = attachable end |
Instance Attribute Details
#attachable ⇒ Object (readonly)
Returns the value of attribute attachable.
11 12 13 |
# File 'lib/active_storage_validations/metadata.rb', line 11 def attachable @attachable end |
Instance Method Details
#metadata ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/active_storage_validations/metadata.rb', line 27 def read_image do |image| if rotated_image?(image) { width: image.height, height: image.width } else { width: image.width, height: image.height } end end rescue InvalidImageError logger.info "Skipping image analysis because ImageMagick or Vips doesn't support the file" {} end |
#valid? ⇒ Boolean
20 21 22 23 24 25 |
# File 'lib/active_storage_validations/metadata.rb', line 20 def valid? read_image true rescue InvalidImageError false end |