Module: Progstr::Filer::Validation
Defined Under Namespace
Classes: AttachmentPropertyValidator, EverythingIncluded
Instance Method Summary
collapse
Instance Method Details
#validates_file_extension_of(attribute, options) ⇒ Object
22
23
24
25
26
27
28
29
30
|
# 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) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# 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
|