Module: ActiveModel::Validations::HelperMethods
- Defined in:
- lib/html5_validators/active_model/helper_methods.rb
Instance Method Summary collapse
- #attribute_max(attribute) ⇒ Object
- #attribute_maxlength(attribute) ⇒ Object
- #attribute_min(attribute) ⇒ Object
- #attribute_required?(attribute) ⇒ Boolean
Instance Method Details
#attribute_max(attribute) ⇒ Object
16 17 18 19 20 |
# File 'lib/html5_validators/active_model/helper_methods.rb', line 16 def attribute_max(attribute) self.validators.grep(NumericalityValidator).select {|v| v.attributes.include?(attribute.to_sym) && (v..keys & [:less_than, :less_than_or_equal_to]).any? && (v..keys & [:if, :unless, :allow_nil, :allow_blank]).empty? }.map {|v| v..slice(:less_than, :less_than_or_equal_to)}.map(&:values).flatten.max end |
#attribute_maxlength(attribute) ⇒ Object
10 11 12 13 14 |
# File 'lib/html5_validators/active_model/helper_methods.rb', line 10 def attribute_maxlength(attribute) self.validators.grep(LengthValidator).select {|v| v.attributes.include?(attribute.to_sym) && (v..keys & [:maximum, :is]).any? && (v..keys & [:if, :unless, :allow_nil, :allow_blank, :tokenizer]).empty? }.map {|v| v..slice(:maximum, :is)}.map(&:values).flatten.max end |
#attribute_min(attribute) ⇒ Object
22 23 24 25 26 |
# File 'lib/html5_validators/active_model/helper_methods.rb', line 22 def attribute_min(attribute) self.validators.grep(NumericalityValidator).select {|v| v.attributes.include?(attribute.to_sym) && (v..keys & [:greater_than, :greater_than_or_equal_to]).any? && (v..keys & [:if, :unless, :allow_nil, :allow_blank]).empty? }.map {|v| v..slice(:greater_than, :greater_than_or_equal_to)}.map(&:values).flatten.min end |
#attribute_required?(attribute) ⇒ Boolean
4 5 6 7 8 |
# File 'lib/html5_validators/active_model/helper_methods.rb', line 4 def attribute_required?(attribute) self.validators.grep(PresenceValidator).any? do |v| v.attributes.include?(attribute.to_sym) && (v..keys & [:if, :unless]).empty? end end |