Sha256: 33421fcd0b74fdb61ee04c47856e8bc4630a68b32537d9a20a7717b7b73647e3

Contents?: true

Size: 627 Bytes

Versions: 5

Compression:

Stored size: 627 Bytes

Contents

# frozen_string_literal: true
module Might
  # Validates sortings and raises error if one of them is invalid
  #
  class SortParametersValidator
    # @param app [#call]
    def initialize(app)
      @app = app
    end

    # @param env [<{:sort => Might::FilterParameter}, Array>]
    # @return [<{:sort => Might::FilterParameter}, Array>]
    #
    def call(env)
      params, errors = env

      not_allowed_parameters = Array(params[:sort]).select(&:invalid?)
      messages = not_allowed_parameters.flat_map(&:errors)

      app.call([params, errors.concat(messages)])
    end

    private

    attr_reader :app
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
might-0.7.6 lib/might/sort_parameters_validator.rb
might-0.7.5 lib/might/sort_parameters_validator.rb
might-0.7.4 lib/might/sort_parameters_validator.rb
might-0.7.3 lib/might/sort_parameters_validator.rb
might-0.7.2 lib/might/sort_parameters_validator.rb