@@ -3,31 +3,31 @@ module Validations
33 module HelperMethods
44 def attribute_required? ( attribute )
55 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?
77 end
88 end
99
1010 def attribute_maxlength ( attribute )
1111 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?
1313 } . map { |v | v . options . slice ( :maximum , :is ) } . map ( &:values ) . flatten . max
1414 end
1515
1616 def attribute_minlength ( attribute )
1717 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?
1919 } . map { |v | v . options . slice ( :minimum , :is ) } . map ( &:values ) . flatten . min
2020 end
2121
2222 def attribute_max ( attribute )
2323 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?
2525 } . map { |v | v . options . slice ( :less_than , :less_than_or_equal_to ) } . map ( &:values ) . flatten . max
2626 end
2727
2828 def attribute_min ( attribute )
2929 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?
3131 } . map { |v | v . options . slice ( :greater_than , :greater_than_or_equal_to ) } . map ( &:values ) . flatten . min
3232 end
3333 end
0 commit comments