Class: MiniDefender::Rules::Required
Class Method Summary
collapse
Instance Method Summary
collapse
#active?, available?, #bails?, #coerce, #default_value, #defaults?, #error_message, #excluded?, #force_coerce?, make, #priority, #stops?, #with_message
Class Method Details
.signature ⇒ Object
6
7
8
|
# File 'lib/mini_defender/rules/required.rb', line 6
def self.signature
'required'
end
|
Instance Method Details
#implicit?(validator) ⇒ Boolean
10
11
12
|
# File 'lib/mini_defender/rules/required.rb', line 10
def implicit?(validator)
true
end
|
#message(attribute, value, validator) ⇒ Object
29
30
31
|
# File 'lib/mini_defender/rules/required.rb', line 29
def message(attribute, value, validator)
"This field is required."
end
|
#passes?(attribute, value, validator) ⇒ Boolean
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/mini_defender/rules/required.rb', line 14
def passes?(attribute, value, validator)
case value
when nil
false
when String
value.strip.length > 0
when Enumerable
value.length > 0
when ActionDispatch::Http::UploadedFile
value.path && value.path.length > 0 && value.size > 0
else
true
end
end
|