module ActiveModel::Validations::HelperMethods

Public Instance Methods

attribute_max(attribute) click to toggle source
# 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.options.keys & [:less_than, :less_than_or_equal_to]).any? && (v.options.keys & [:if, :unless, :allow_nil, :allow_blank]).empty?
      !(on = v.options[:on]) || Array(on).include?(default_validation_context)
    end
  }.map {|v| v.options.slice(:less_than, :less_than_or_equal_to)}.map(&:values).flatten.max
end
attribute_maxlength(attribute) click to toggle source
# 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.options.keys & [:maximum, :is]).any? && (v.options.keys & [:if, :unless, :tokenizer]).empty?
      !(on = v.options[:on]) || Array(on).include?(default_validation_context)
    end
  }.map {|v| v.options.slice(:maximum, :is)}.map(&:values).flatten.max
end
attribute_min(attribute) click to toggle source
# 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.options.keys & [:greater_than, :greater_than_or_equal_to]).any? && (v.options.keys & [:if, :unless, :allow_nil, :allow_blank]).empty?
      !(on = v.options[:on]) || Array(on).include?(default_validation_context)
    end
  }.map {|v| v.options.slice(:greater_than, :greater_than_or_equal_to)}.map(&:values).flatten.min
end
attribute_minlength(attribute) click to toggle source
# 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.options.keys & [:minimum, :is]).any? && (v.options.keys & [:if, :unless, :allow_nil, :allow_blank, :tokenizer]).empty?
      !(on = v.options[:on]) || Array(on).include?(default_validation_context)
    end
  }.map {|v| v.options.slice(:minimum, :is)}.map(&:values).flatten.min
end
attribute_required?(attribute) click to toggle source
# 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.options.keys & [:if, :unless]).empty?
      !(on = v.options[:on]) || Array(on).include?(default_validation_context)
    end
  end
end