Sha256: fcbbad47a6e48ff15682151837a53a71567ca18eb2171d695b0f2e09d6c63047

Contents?: true

Size: 613 Bytes

Versions: 5

Compression:

Stored size: 613 Bytes

Contents

# frozen_string_literal: true
module Might
  # Sort scope using ransack gem
  #
  class SortMiddleware
    # @param app [#call]
    #
    def initialize(app)
      @app = app
    end

    attr_reader :app

    # @param [Array(ActiveRecord::Relation, Hash)] env
    # First argument is a ActiveRecord relation which must be sorted
    # Second argument is a request parameters provided by user
    #
    def call(env)
      scope, = ::Middleware::Builder.new do |b|
        b.use RansackableSortParametersAdapter
        b.use RansackableSort
      end.call(env)

      app.call([scope, env[1]])
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

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