Sha256: 51cc414df3ea77d4fa9c742e879e04fff6d718c691512f77d560a48d2ee5ffe1

Contents?: true

Size: 606 Bytes

Versions: 5

Compression:

Stored size: 606 Bytes

Contents

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

    # @param env [<ActiveRecord::Relation, <String>]
    #   * first element is a scope to be sorted
    #   * second is a array with user provided sortings
    # @return [<ActiveRecord::Relation, <String>]
    #
    def call(env)
      scope, params = env

      ransackable_query = scope.ransack
      ransackable_query.sorts = params[:sort]

      app.call([ransackable_query.result, params])
    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/ransackable_sort.rb
might-0.7.5 lib/might/ransackable_sort.rb
might-0.7.4 lib/might/ransackable_sort.rb
might-0.7.3 lib/might/ransackable_sort.rb
might-0.7.2 lib/might/ransackable_sort.rb