class Judge::ValidatorCollection
Constants
- UNSUPPORTED_OPTIONS
Attributes
method[R]
object[R]
validators[R]
Public Class Methods
new(object, method)
click to toggle source
# File lib/judge/validator_collection.rb, line 9 def initialize(object, method) @object = object @method = method @validators = amvs.map { |amv| Judge::Validator.new(object, method, amv) } end
Public Instance Methods
each(&block)
click to toggle source
# File lib/judge/validator_collection.rb, line 15 def each(&block) validators.each do |v| block.call(v) end end
to_json()
click to toggle source
# File lib/judge/validator_collection.rb, line 21 def to_json validators.map { |v| v.to_hash }.to_json end
Protected Instance Methods
amvs()
click to toggle source
returns an array of ActiveModel::Validations starts with all Validations attached to method and removes one that are:
ignored based on a config ConfirmationValidators, which are moved directly to the confirmation method unsupported by Judge
if it's a confirmation field, an AM::V like class is added to handle the confirmation validations
# File lib/judge/validator_collection.rb, line 35 def amvs amvs = object.class.validators_on(method) amvs = amvs.reject { |amv| reject?(amv) || amv.class.name['ConfirmationValidator'] } amvs = amvs.reject { |amv| unsupported_options?(amv) && reject?(amv) != false } if Judge.config.ignore_unsupported_validators? amvs << Judge::ConfirmationValidator.new(object, method) if is_confirmation? amvs end
is_confirmation?()
click to toggle source
# File lib/judge/validator_collection.rb, line 64 def is_confirmation? method.to_s['_confirmation'] end
reject?(amv)
click to toggle source
decides whether to reject a validation based on the presence of the judge option. return values:
true when :judge => :ignore is present in the options false when :judge => :force is present nil otherwise (e.g. when no :judge option or an unknown option is present)
# File lib/judge/validator_collection.rb, line 59 def reject?(amv) return unless [:force, :ignore].include?( amv.options[:judge] ) amv.options[:judge] == :ignore end
unsupported_options?(amv)
click to toggle source
# File lib/judge/validator_collection.rb, line 44 def unsupported_options?(amv) unsupported = !(amv.options.keys & UNSUPPORTED_OPTIONS).empty? return false unless unsupported # Apparently, uniqueness validations always have the case_sensitive option, even # when it is not explicitly used (in which case it has value true). Hence, we only # report the validation as unsupported when case_sensitive is set to false. unsupported = amv.options.keys & UNSUPPORTED_OPTIONS unsupported.length > 1 || unsupported != [:case_sensitive] || amv.options[:case_sensitive] == false end