Class: Paperclip::Validate::SizeValidator
- Inherits:
-
DataMapper::Validate::GenericValidator
- Object
- DataMapper::Validate::GenericValidator
- Paperclip::Validate::SizeValidator
- Defined in:
- lib/dm-paperclip/validations.rb
Overview
:nodoc:
Instance Method Summary collapse
Instance Method Details
#call(target) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/dm-paperclip/validations.rb', line 37 def call(target) field_value = target.validation_property_value(:"#{@field_name}_file_size") return true if field_value.nil? [:in] = ([:greater_than]..(1/0)) unless [:greater_than].nil? [:in] = (0..[:less_than]) unless [:less_than].nil? return true if [:in].include? field_value.to_i ||= [:message] unless [:message].nil? ||= sprintf("%s must be less than %s bytes", @field_name.to_s.humanize, [:less_than]) unless [:less_than].nil? ||= sprintf("%s must be greater than %s bytes", @field_name.to_s.humanize, [:greater_than]) unless [:greater_than].nil? ||= sprintf("%s must be between %s and %s bytes", @field_name.to_s.humanize, [:in].first, [:in].last) add_error(target, , @field_name) return false end |