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
49 50 51 52 53 54 55 |
# File 'lib/html5_validators/active_model/helper_methods.rb', line 49 def attribute_max(attribute) self.class.validators.grep(NumericalityValidator).select {|v| if 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? !(on = v.[:on]) || Array(on).include?(default_validation_context) end }.map {|v| v..slice(:less_than, :less_than_or_equal_to)}.map(&:values).flatten.max end |
#attribute_maxlength(attribute) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/html5_validators/active_model/helper_methods.rb', line 33 def attribute_maxlength(attribute) self.class.validators.grep(LengthValidator).select {|v| if v.attributes.include?(attribute.to_sym) && (v..keys & [:maximum, :is]).any? && (v..keys & [:if, :unless, :tokenizer]).empty? !(on = v.[:on]) || Array(on).include?(default_validation_context) end }.map {|v| v..slice(:maximum, :is)}.map(&:values).flatten.max end |
#attribute_min(attribute) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/html5_validators/active_model/helper_methods.rb', line 57 def attribute_min(attribute) self.class.validators.grep(NumericalityValidator).select {|v| if 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? !(on = v.[:on]) || Array(on).include?(default_validation_context) end }.map {|v| v..slice(:greater_than, :greater_than_or_equal_to)}.map(&:values).flatten.min end |
#attribute_minlength(attribute) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/html5_validators/active_model/helper_methods.rb', line 41 def attribute_minlength(attribute) self.class.validators.grep(LengthValidator).select {|v| if v.attributes.include?(attribute.to_sym) && (v..keys & [:minimum, :is]).any? && (v..keys & [:if, :unless, :allow_nil, :allow_blank, :tokenizer]).empty? !(on = v.[:on]) || Array(on).include?(default_validation_context) end }.map {|v| v..slice(:minimum, :is)}.map(&:values).flatten.min end |
#attribute_required?(attribute) ⇒ Boolean
25 26 27 28 29 30 31 |
# File 'lib/html5_validators/active_model/helper_methods.rb', line 25 def attribute_required?(attribute) self.class.validators.grep(PresenceValidator).any? do |v| if v.attributes.include?(attribute.to_sym) && (v..keys & [:if, :unless]).empty? !(on = v.[:on]) || Array(on).include?(default_validation_context) end end end |