module Progstr::Filer::Validation

Public Instance Methods

validates_file_extension_of(attribute, options) click to toggle source
# File lib/filer/validation.rb, line 22
def validates_file_extension_of(attribute, options)
  allowed = options[:allowed] || EverythingIncluded.new
  message = options[:message] || "File extension not allowed."

  validates_with AttachmentPropertyValidator, :attributes => [attribute],
    :property => :extension,
    :in        => allowed,
    :message   => message
end
validates_file_size_of(attribute, options) click to toggle source
# File lib/filer/validation.rb, line 6
def validates_file_size_of(attribute, options)
  range = options[:in] || (0..1.0/0)
  min = options[:greater_than] || range.first
  max = options[:less_than]    || range.last
  allowed_range = (min..max)

  message = options[:message] || "File size not between #{min} and #{max} bytes."

  validates_with AttachmentPropertyValidator, :attributes => [attribute],
    :property => :size,
    :in        => allowed_range,
    :message   => message,
    :allow_blank => true,
    :allow_nil => true
end