Class: Quo::CollectionResults
- Defined in:
- lib/quo/collection_results.rb,
sig/generated/quo/collection_results.rbs
Overview
Results wrapper for collection-backed queries providing pagination and counting
Constant Summary
Constants inherited from Results
Results::FILTER_METHODS, Results::PAIR_FILTER_METHODS, Results::PASSTHROUGH_METHODS
Instance Method Summary collapse
-
#empty? ⇒ Boolean
: bool.
-
#exists? ⇒ Boolean
Are there any results for this query?.
-
#initialize(query, transformer: nil, total_count: nil) ⇒ CollectionResults
constructor
A new instance of CollectionResults.
-
#page_count ⇒ Integer
Gets the actual count of elements in the page of results (assuming paging is being used, otherwise the count of all results).
-
#total_count ⇒ void
Gets the count of all results ignoring the current page and page size (if set).
Methods inherited from Results
#count, #group_by, #method_missing, #page_size, #respond_to_missing?, #size, #transform?, #transform_pair, #transform_results
Constructor Details
#initialize(query, transformer: nil, total_count: nil) ⇒ CollectionResults
Returns a new instance of CollectionResults.
9 10 11 12 13 14 15 |
# File 'lib/quo/collection_results.rb', line 9 def initialize(query, transformer: nil, total_count: nil) raise ArgumentError, "Query must be a CollectionBackedQuery" unless query.is_a?(Quo::CollectionBackedQuery) @total_count = total_count @query = query @configured_query = query.unwrap @transformer = transformer end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Quo::Results
Instance Method Details
#empty? ⇒ Boolean
: bool
22 23 24 |
# File 'lib/quo/collection_results.rb', line 22 def empty? #: bool !exists? end |
#exists? ⇒ Boolean
Are there any results for this query?
18 19 20 |
# File 'lib/quo/collection_results.rb', line 18 def exists? #: bool @configured_query.present? end |
#page_count ⇒ Integer
Gets the actual count of elements in the page of results (assuming paging is being used, otherwise the count of all results)
37 38 39 |
# File 'lib/quo/collection_results.rb', line 37 def page_count #: Integer @configured_query.size end |
#total_count ⇒ void
This method returns an undefined value.
Gets the count of all results ignoring the current page and page size (if set).
Optionally return the total_count option if it has been set.
This is useful when the total count is known and not equal to size
of wrapped collection.
31 32 33 |
# File 'lib/quo/collection_results.rb', line 31 def total_count #: Integer @total_count || @query.unwrap_unpaginated.size end |