Sha256: e77ea23a72f8b9a0d613eabcc9afbdf9477316daa9a8454bd91a1f2427d3f4c4

Contents?: true

Size: 576 Bytes

Versions: 9

Compression:

Stored size: 576 Bytes

Contents

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

9 entries across 9 versions & 1 rubygems

Version Path
might-0.7.1 lib/might/ransackable_sort.rb
might-0.7.0 lib/might/ransackable_sort.rb
might-0.6.0 lib/might/ransackable_sort.rb
might-0.5.2 lib/might/ransackable_sort.rb
might-0.5.1 lib/might/ransackable_sort.rb
might-0.5.0 lib/might/ransackable_sort.rb
might-0.4.0 lib/might/ransackable_sort.rb
might-0.3.1 lib/might/ransackable_sort.rb
might-0.3.0 lib/might/ransackable_sort.rb