Class: JSONAPI::CollectionQuery
- Inherits:
-
Object
- Object
- JSONAPI::CollectionQuery
- Includes:
- Support::ConditionBuilding, Support::NestedFilters, Support::Pagination, Support::PolymorphicFilters, Support::RegularFilters, Support::Sorting
- Defined in:
- lib/json_api/support/collection_query.rb
Instance Attribute Summary collapse
-
#pagination_applied ⇒ Object
readonly
Returns the value of attribute pagination_applied.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(scope, definition:, model_class:, filter_params:, sort_params:, page_params:) ⇒ CollectionQuery
constructor
A new instance of CollectionQuery.
Methods included from Support::Pagination
Methods included from Support::PolymorphicFilters
#apply_polymorphic_nested_filters
Methods included from Support::NestedFilters
#apply_nested_relationship_filters
Methods included from Support::RegularFilters
Methods included from Support::Sorting
Constructor Details
#initialize(scope, definition:, model_class:, filter_params:, sort_params:, page_params:) ⇒ CollectionQuery
Returns a new instance of CollectionQuery.
21 22 23 24 25 26 27 28 29 |
# File 'lib/json_api/support/collection_query.rb', line 21 def initialize(scope, definition:, model_class:, filter_params:, sort_params:, page_params:) @scope = scope @definition = definition @model_class = model_class @filter_params = filter_params @sort_params = sort_params @page_params = page_params @pagination_applied = page_params.present? end |
Instance Attribute Details
#pagination_applied ⇒ Object (readonly)
Returns the value of attribute pagination_applied.
19 20 21 |
# File 'lib/json_api/support/collection_query.rb', line 19 def pagination_applied @pagination_applied end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
19 20 21 |
# File 'lib/json_api/support/collection_query.rb', line 19 def scope @scope end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
19 20 21 |
# File 'lib/json_api/support/collection_query.rb', line 19 def total_count @total_count end |
Instance Method Details
#execute ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/json_api/support/collection_query.rb', line 31 def execute @scope = apply_filtering has_virtual_sort = sort_params.any? { |sort_field| virtual_attribute_sort?(sort_field) } @total_count = @scope.count unless has_virtual_sort @scope = apply_sorting(@scope) @total_count = @scope.count if has_virtual_sort && @scope.is_a?(Array) @scope = apply_pagination self end |