Class: MiniDefender::Rules::Boolean
Class Method Summary
collapse
Instance Method Summary
collapse
#active?, available?, #bails?, #default_value, #defaults?, #error_message, #excluded?, #force_coerce?, #implicit?, make, #priority, #stops?, #with_message
Class Method Details
.signature ⇒ Object
4
5
6
|
# File 'lib/mini_defender/rules/boolean.rb', line 4
def self.signature
'boolean'
end
|
Instance Method Details
#coerce(value) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/mini_defender/rules/boolean.rb', line 8
def coerce(value)
value = value.downcase if value.is_a?(String)
case value
when 0, '0', 'no', 'off', 'false'
false
when 1, '1', 'yes', 'on', 'true'
true
else
value
end
end
|
#message(attribute, value, validator) ⇒ Object
26
27
28
|
# File 'lib/mini_defender/rules/boolean.rb', line 26
def message(attribute, value, validator)
'The value must be a boolean, yes, no, on, off, 0 or 1.'
end
|
#passes?(attribute, value, validator) ⇒ Boolean
20
21
22
23
24
|
# File 'lib/mini_defender/rules/boolean.rb', line 20
def passes?(attribute, value, validator)
value = value.downcase if value.is_a?(String)
value.is_a?(TrueClass) || value.is_a?(FalseClass) ||
[1, 0, '1', '0', 'yes', 'no', 'on', 'off', 'true', 'false'].include?(value)
end
|