class Right::SortParametersValidator

Validates sortings and raises error if one of them is invalid

Attributes

app[R]

Public Class Methods

new(app) click to toggle source

@param app [#call]

# File lib/right/sort_parameters_validator.rb, line 7
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source

@param env [<{:sort => Right::FilterParameter}, Array>] @return [<{:sort => Right::FilterParameter}, Array>]

# File lib/right/sort_parameters_validator.rb, line 14
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