@@ -3,31 +3,31 @@ module Validations
3
3
module HelperMethods
4
4
def attribute_required? ( attribute )
5
5
self . validators . grep ( PresenceValidator ) . any? do |v |
6
- v . attributes . include? ( attribute . to_sym ) && ( v . options . keys & [ :if , :unless ] ) . empty?
6
+ v . attributes . include? ( attribute . to_sym ) && ( v . options . keys & [ :if , :unless , :on ] ) . empty?
7
7
end
8
8
end
9
9
10
10
def attribute_maxlength ( attribute )
11
11
self . validators . grep ( LengthValidator ) . select { |v |
12
- v . attributes . include? ( attribute . to_sym ) && ( v . options . keys & [ :maximum , :is ] ) . any? && ( v . options . keys & [ :if , :unless , :allow_nil , :allow_blank , :tokenizer ] ) . empty?
12
+ v . attributes . include? ( attribute . to_sym ) && ( v . options . keys & [ :maximum , :is ] ) . any? && ( v . options . keys & [ :if , :unless , :on , : allow_nil, :allow_blank , :tokenizer ] ) . empty?
13
13
} . map { |v | v . options . slice ( :maximum , :is ) } . map ( &:values ) . flatten . max
14
14
end
15
15
16
16
def attribute_minlength ( attribute )
17
17
self . validators . grep ( LengthValidator ) . select { |v |
18
- v . attributes . include? ( attribute . to_sym ) && ( v . options . keys & [ :minimum , :is ] ) . any? && ( v . options . keys & [ :if , :unless , :allow_nil , :allow_blank , :tokenizer ] ) . empty?
18
+ v . attributes . include? ( attribute . to_sym ) && ( v . options . keys & [ :minimum , :is ] ) . any? && ( v . options . keys & [ :if , :unless , :on , : allow_nil, :allow_blank , :tokenizer ] ) . empty?
19
19
} . map { |v | v . options . slice ( :minimum , :is ) } . map ( &:values ) . flatten . min
20
20
end
21
21
22
22
def attribute_max ( attribute )
23
23
self . validators . grep ( NumericalityValidator ) . select { |v |
24
- v . attributes . include? ( attribute . to_sym ) && ( v . options . keys & [ :less_than , :less_than_or_equal_to ] ) . any? && ( v . options . keys & [ :if , :unless , :allow_nil , :allow_blank ] ) . empty?
24
+ v . attributes . include? ( attribute . to_sym ) && ( v . options . keys & [ :less_than , :less_than_or_equal_to ] ) . any? && ( v . options . keys & [ :if , :unless , :on , : allow_nil, :allow_blank ] ) . empty?
25
25
} . map { |v | v . options . slice ( :less_than , :less_than_or_equal_to ) } . map ( &:values ) . flatten . max
26
26
end
27
27
28
28
def attribute_min ( attribute )
29
29
self . validators . grep ( NumericalityValidator ) . select { |v |
30
- v . attributes . include? ( attribute . to_sym ) && ( v . options . keys & [ :greater_than , :greater_than_or_equal_to ] ) . any? && ( v . options . keys & [ :if , :unless , :allow_nil , :allow_blank ] ) . empty?
30
+ v . attributes . include? ( attribute . to_sym ) && ( v . options . keys & [ :greater_than , :greater_than_or_equal_to ] ) . any? && ( v . options . keys & [ :if , :unless , :on , : allow_nil, :allow_blank ] ) . empty?
31
31
} . map { |v | v . options . slice ( :greater_than , :greater_than_or_equal_to ) } . map ( &:values ) . flatten . min
32
32
end
33
33
end
0 commit comments