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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dm-paperclip/validations.rb', line 44 def call(target) field_value = target.validation_property_value(:"#{@field_name}_file_size") return true if field_value.nil? [:in] = ([:greater_than]..(1.0/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",DataMapper::Inflector.humanize(@field_name), [:less_than]) unless [:less_than].nil? ||= sprintf("%s must be greater than %s bytes",DataMapper::Inflector.humanize(@field_name), [:greater_than]) unless [:greater_than].nil? ||= sprintf("%s must be between %s and %s bytes",DataMapper::Inflector.humanize(@field_name), [:in].first, [:in].last) add_error(target, , @field_name) return false end |