Class: MiniDefender::Rules::Between
Class Method Summary
collapse
Instance Method Summary
collapse
#active?, available?, #bails?, #coerce, #default_value, #defaults?, #error_message, #excluded?, #force_coerce?, #implicit?, #priority, #stops?, #with_message
Constructor Details
#initialize(min, max) ⇒ Between
Returns a new instance of Between.
4
5
6
7
|
# File 'lib/mini_defender/rules/between.rb', line 4
def initialize(min, max)
@min = min
@max = max
end
|
Class Method Details
.make(args) ⇒ Object
13
14
15
|
# File 'lib/mini_defender/rules/between.rb', line 13
def self.make(args)
self.new(args[0].to_i, args[1].to_i)
end
|
.signature ⇒ Object
9
10
11
|
# File 'lib/mini_defender/rules/between.rb', line 9
def self.signature
'between'
end
|
Instance Method Details
#message(attribute, value, validator) ⇒ Object
26
27
28
|
# File 'lib/mini_defender/rules/between.rb', line 26
def message(attribute, value, validator)
"The value length must be between #{@min} and #{@max}."
end
|
#passes?(attribute, value, validator) ⇒ Boolean
17
18
19
20
21
22
23
24
|
# File 'lib/mini_defender/rules/between.rb', line 17
def passes?(attribute, value, validator)
case value
when String, Array, Hash
@min <= value.length && value.length <= @max
else
false
end
end
|