Class: Paperclip::Validators::AttachmentDimensionsValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Paperclip::Validators::AttachmentDimensionsValidator
- Defined in:
- lib/paperclip/validators/attachment_dimensions_validator.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ AttachmentDimensionsValidator
constructor
A new instance of AttachmentDimensionsValidator.
- #validate_each(record, attribute, value) ⇒ Object
Constructor Details
#initialize(options) ⇒ AttachmentDimensionsValidator
Returns a new instance of AttachmentDimensionsValidator.
4 5 6 |
# File 'lib/paperclip/validators/attachment_dimensions_validator.rb', line 4 def initialize() super end |
Class Method Details
.helper_method_name ⇒ Object
8 9 10 |
# File 'lib/paperclip/validators/attachment_dimensions_validator.rb', line 8 def self.helper_method_name :validates_attachment_dimensions end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/paperclip/validators/attachment_dimensions_validator.rb', line 12 def validate_each(record, attribute, value) dimensions = Paperclip::Geometry.from_file(value.queued_for_write[:original].path) [:height, :width].each do |dimension| if [dimension] && dimensions.send(dimension) != [dimension].to_f record.errors.add(attribute.to_sym, :dimension, dimension_type: dimension.to_s, dimension: [dimension], actual_dimension: dimensions.send(dimension).to_i) end end end |