Module: Filterable::Datable::Since

Defined in:
lib/filterable/datable/since.rb

Overview

Keeps rows whose datable attribute is on or before the bound (inclusive). Reads filters[<attribute>][since].

Class Method Summary collapse

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 on or before each declared attribute's since bound.

Parameters:

  • params (Hash, ActionController::Parameters)

    the nested filters params.

  • scope (ActiveRecord::Relation)

    the relation being filtered.

Returns:

  • (ActiveRecord::Relation)

    the narrowed relation.



16
17
18
19
20
21
22
23
# File 'lib/filterable/datable/since.rb', line 16

def call(params, scope)
  Filterable::Datable.columns(params, scope).reduce(scope) do |sub_scope, (column, bounds)|
    since = Filterable::Datable.parse(bounds[:since])
    next sub_scope unless since

    sub_scope.where(scope.arel_table[column].lteq(since))
  end
end