Sha256: 83546727074d99a1dc18c14f8a68054983dd40bfcbf69613fb491a8a64b587ca

Contents?: true

Size: 684 Bytes

Versions: 15

Compression:

Stored size: 684 Bytes

Contents

# frozen_string_literal: true

class Grumlin::QueryValidators::Validator
  class ValidationError < Grumlin::Error
    attr_reader :errors, :steps

    def initialize(steps, errors)
      super("Query is invalid: #{errors}")
      @steps = steps
      @errors = errors
    end
  end

  # steps is an instance of `Steps` after shortcuts applied
  def validate!(steps)
    return unless (err = errors(steps)).any?

    raise ValidationError.new(steps, err)
  end

  def valid?(steps)
    errors(steps).empty?
  end

  protected

  def errors(steps)
    {}.tap do |errors|
      validate(steps, errors)
    end
  end

  def validate(steps, errors)
    raise NotImplementedError
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
grumlin-1.2.0 lib/grumlin/query_validators/validator.rb
grumlin-1.1.0 lib/grumlin/query_validators/validator.rb
grumlin-1.0.4 lib/grumlin/query_validators/validator.rb
grumlin-1.0.3 lib/grumlin/query_validators/validator.rb
grumlin-1.0.3.beta1 lib/grumlin/query_validators/validator.rb
grumlin-1.0.2 lib/grumlin/query_validators/validator.rb
grumlin-1.0.1 lib/grumlin/query_validators/validator.rb
grumlin-1.0.0 lib/grumlin/query_validators/validator.rb
grumlin-1.0.0.rc7 lib/grumlin/query_validators/validator.rb
grumlin-1.0.0.rc6 lib/grumlin/query_validators/validator.rb
grumlin-1.0.0.rc5 lib/grumlin/query_validators/validator.rb
grumlin-1.0.0.rc4 lib/grumlin/query_validators/validator.rb
grumlin-1.0.0.rc3 lib/grumlin/query_validators/validator.rb
grumlin-1.0.0.rc2 lib/grumlin/query_validators/validator.rb
grumlin-1.0.0.rc1 lib/grumlin/query_validators/validator.rb