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/scope_resolver.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, ScopeResolver, Sorts Classes: Filter, Retriever, Sort
Constant Summary collapse
- VALID_TYPES =
Returns the types
filter_on/sort_onrecognize for theirtype:option. %i[string text integer boolean date datetime time scope].freeze
- VERSION =
Returns the current gem version.
"1.2.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
Filter params.
-
#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>
Sort param split.
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.
36 37 38 |
# File 'lib/toller.rb', line 36 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.
105 106 107 |
# File 'lib/toller.rb', line 105 def filter_param_key :filters end |
#filter_params ⇒ Hash
Filter params
88 89 90 |
# File 'lib/toller.rb', line 88 def filter_params params.fetch(filter_param_key.to_sym, {}).transform_keys { |key| key.to_s.strip.downcase } end |
#retrieve(collection) ⇒ ActiveRecord::Relation
Applies every active filter/sort for the current request to collection.
45 46 47 |
# File 'lib/toller.rb', line 45 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.
114 115 116 |
# File 'lib/toller.rb', line 114 def sort_param_key :sort end |
#sort_params ⇒ Array<String>
Sort param split
96 97 98 |
# File 'lib/toller.rb', line 96 def sort_params params.fetch(sort_param_key.to_sym, "").split(",").map { |param| param.strip.downcase }.reject(&:empty?) end |