Sha256: 8779c2dd85ea7ebe5ef9704d024ca2bd9a4365f4d7e226b17209e1c86589ff14

Contents?: true

Size: 585 Bytes

Versions: 4

Compression:

Stored size: 585 Bytes

Contents

module Judge

  class ValidatorCollection

    include Enumerable

    attr_reader :validators
    
    def initialize(object, method)
      active_model_validators = object.class.validators_on(method).reject { |amv| amv.kind == :uniqueness }
      @validators = active_model_validators.map do |amv|
        Judge::Validator.new(amv, method, Judge::MessageCollection.new(object, method, amv))
      end
    end

    def each(&block)
      validators.each do |v|
        block.call(v)
      end
    end

    def to_json
      validators.map { |v| v.to_hash }.to_json
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
judge-1.4.0 lib/judge/validator_collection.rb
judge-1.3.0 lib/judge/validator_collection.rb
judge-1.2.0 lib/judge/validator_collection.rb
judge-1.1.0 lib/judge/validator_collection.rb