Module: Toller
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/toller.rb,
lib/toller/sort.rb,
lib/toller/filter.rb,
lib/toller/version.rb,
lib/toller/retriever.rb,
lib/toller/sorts/scope_handler.rb,
lib/toller/sorts/column_handler.rb,
lib/toller/filters/mutators/date.rb,
lib/toller/filters/mutators/time.rb,
lib/toller/filters/scope_handler.rb,
lib/toller/filters/column_handler.rb,
lib/toller/filters/mutators/boolean.rb,
lib/toller/filters/mutators/integer.rb,
lib/toller/filters/mutators/datetime.rb,
lib/toller/filters/mutators/common/range.rb
Overview
Toller
Query param based filtering and sorting
Defined Under Namespace
Modules: Filters, Sorts Classes: Filter, Retriever, Sort
Constant Summary collapse
- VERSION =
Returns the current gem version.
"1.1.0"
Class Method Summary collapse
-
.truthy(value) ⇒ Boolean
Coerces a raw string value into a boolean, using the same rule Toller's own
type: :booleanfilters use internally.
Instance Method Summary collapse
-
#filter_param_key ⇒ Symbol
Override in an including controller to change the query param Toller reads filters from.
-
#filter_params ⇒ Hash
The current request's filter params, keyed by filter parameter name.
-
#retrieve(collection) ⇒ ActiveRecord::Relation
Applies every active filter/sort for the current request to
collection. -
#sort_param_key ⇒ Symbol
Override in an including controller to change the query param Toller reads sorts from.
-
#sort_params ⇒ Array<String>
The current request's sort params, e.g.
Class Method Details
.truthy(value) ⇒ Boolean
Coerces a raw string value into a boolean, using the same rule Toller's
own type: :boolean filters use internally. Handy inside a model scope
backing a type: :scope filter, which receives the raw param value
unmutated.
32 33 34 |
# File 'lib/toller.rb', line 32 def self.truthy(value) Filters::Mutators::Boolean.call(value) end |
Instance Method Details
#filter_param_key ⇒ Symbol
Override in an including controller to change the query param Toller reads filters from.
97 98 99 |
# File 'lib/toller.rb', line 97 def filter_param_key :filters end |
#filter_params ⇒ Hash
Returns the current request's filter params, keyed by filter parameter name.
82 83 84 |
# File 'lib/toller.rb', line 82 def filter_params params.fetch(filter_param_key.to_sym, {}) end |
#retrieve(collection) ⇒ ActiveRecord::Relation
Applies every active filter/sort for the current request to collection.
41 42 43 |
# File 'lib/toller.rb', line 41 def retrieve(collection) Retriever.filter(collection, filter_params, sort_params, retrievals) end |
#sort_param_key ⇒ Symbol
Override in an including controller to change the query param Toller reads sorts from.
106 107 108 |
# File 'lib/toller.rb', line 106 def sort_param_key :sort end |
#sort_params ⇒ Array<String>
Returns the current request's sort params, e.g. ['-published_at', 'title'].
88 89 90 |
# File 'lib/toller.rb', line 88 def sort_params params.fetch(sort_param_key.to_sym, "").split(",") end |