Module: Filterable::Datable::Range
- Defined in:
- lib/filterable/datable/range.rb
Overview
Keeps rows whose datable attribute falls within an inclusive range.
Reads filters[<attribute>][from] and filters[<attribute>][to], applied
only when both bounds are present and parseable.
Class Method Summary collapse
-
.call(params, scope) ⇒ ActiveRecord::Relation
private
Narrows the scope to rows within each declared attribute's inclusive +from+/+to+ range.
Class Method Details
.call(params, scope) ⇒ ActiveRecord::Relation
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Narrows the scope to rows within each declared attribute's inclusive +from+/+to+ range.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/filterable/datable/range.rb', line 17 def call(params, scope) Filterable::Datable.columns(params, scope).reduce(scope) do |sub_scope, (column, bounds)| from = Filterable::Datable.parse(bounds[:from]) to = Filterable::Datable.parse(bounds[:to]) next sub_scope unless from && to field = scope.arel_table[column] sub_scope.where(field.gteq(from)).where(field.lteq(to)) end end |