Class: Might::RansackableSortParametersAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/might/ransackable_sort_parameters_adapter.rb

Overview

Converts array of parameters to hash familiar to ransack gem

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RansackableSortParametersAdapter

Returns a new instance of RansackableSortParametersAdapter.



6
7
8
# File 'lib/might/ransackable_sort_parameters_adapter.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/might/ransackable_sort_parameters_adapter.rb', line 10

def call(env)
  scope, params = env

  ransackable_parameters = Array(params[:sort]).map do |parameter|
    "#{parameter.name} #{parameter.direction}"
  end

  app.call([scope, params.merge(sort: ransackable_parameters)])
end