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_minlength(attribute) ⇒ Object
- #attribute_required?(attribute) ⇒ Boolean
Instance Method Details
#attribute_max(attribute) ⇒ Object
23 24 25 26 27 |
# File 'lib/html5_validators/active_model/helper_methods.rb', line 23 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
11 12 13 14 15 |
# File 'lib/html5_validators/active_model/helper_methods.rb', line 11 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, :tokenizer]).empty? }.map {|v| v..slice(:maximum, :is)}.map(&:values).flatten.max end |
#attribute_min(attribute) ⇒ Object
29 30 31 32 33 |
# File 'lib/html5_validators/active_model/helper_methods.rb', line 29 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_minlength(attribute) ⇒ Object
17 18 19 20 21 |
# File 'lib/html5_validators/active_model/helper_methods.rb', line 17 def attribute_minlength(attribute) self.validators.grep(LengthValidator).select {|v| v.attributes.include?(attribute.to_sym) && (v..keys & [:minimum, :is]).any? && (v..keys & [:if, :unless, :allow_nil, :allow_blank, :tokenizer]).empty? }.map {|v| v..slice(:minimum, :is)}.map(&:values).flatten.min end |
#attribute_required?(attribute) ⇒ Boolean
5 6 7 8 9 |
# File 'lib/html5_validators/active_model/helper_methods.rb', line 5 def attribute_required?(attribute) self.validators.grep(PresenceValidator).any? do |v| v.attributes.include?(attribute.to_sym) && (v..keys & [:if, :unless]).empty? end end |