Class: JsonApiFilter::Dispatch
- Inherits:
-
Object
- Object
- JsonApiFilter::Dispatch
- Defined in:
- lib/json_api_filter/dispatch.rb
Instance Attribute Summary collapse
-
#allowed_filters ⇒ Object
readonly
Returns the value of attribute allowed_filters.
-
#allowed_searches ⇒ Object
readonly
Returns the value of attribute allowed_searches.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
-
#initialize(scope, params, allowed_filters:, allowed_searches:) ⇒ Dispatch
constructor
A new instance of Dispatch.
- #process ⇒ ActiveRecord_Relation
Constructor Details
#initialize(scope, params, allowed_filters:, allowed_searches:) ⇒ Dispatch
Returns a new instance of Dispatch.
9 10 11 12 13 14 |
# File 'lib/json_api_filter/dispatch.rb', line 9 def initialize(scope, params, allowed_filters:, allowed_searches:) @params = params @scope = scope @allowed_filters = allowed_filters @allowed_searches = allowed_searches end |
Instance Attribute Details
#allowed_filters ⇒ Object (readonly)
Returns the value of attribute allowed_filters.
4 5 6 |
# File 'lib/json_api_filter/dispatch.rb', line 4 def allowed_filters @allowed_filters end |
#allowed_searches ⇒ Object (readonly)
Returns the value of attribute allowed_searches.
4 5 6 |
# File 'lib/json_api_filter/dispatch.rb', line 4 def allowed_searches @allowed_searches end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
4 5 6 |
# File 'lib/json_api_filter/dispatch.rb', line 4 def params @params end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
4 5 6 |
# File 'lib/json_api_filter/dispatch.rb', line 4 def scope @scope end |
Instance Method Details
#process ⇒ ActiveRecord_Relation
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/json_api_filter/dispatch.rb', line 17 def process @scope = [ scope.all, sort_predicate, filters_predicate, search_predicate, join_predicate, ].compact.reduce(&:merge) return scope if params[:pagination].nil? scope.merge(pagination_predicate) end |