Sha256: 5fd786c7324df5a316d4f33aa21ac24862c6b6ef5f975d6b02e80ad35778d79e

Contents?: true

Size: 522 Bytes

Versions: 9

Compression:

Stored size: 522 Bytes

Contents

module Might
  #
  class RansackableFilter
    # @param app [#call]
    def initialize(app)
      @app = app
    end

    # @param env [<ActiveRecord::Relation, Hash]
    #   * first element is a scope to be filtered
    #   * second is a hash with user provided filters
    # @return [<ActiveRecord::Relation, Hash]
    #
    def call(env)
      scope, params = env
      filtered_scope = scope.ransack(params[:filter]).result
      app.call([filtered_scope, 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_filter.rb
might-0.7.0 lib/might/ransackable_filter.rb
might-0.6.0 lib/might/ransackable_filter.rb
might-0.5.2 lib/might/ransackable_filter.rb
might-0.5.1 lib/might/ransackable_filter.rb
might-0.5.0 lib/might/ransackable_filter.rb
might-0.4.0 lib/might/ransackable_filter.rb
might-0.3.1 lib/might/ransackable_filter.rb
might-0.3.0 lib/might/ransackable_filter.rb