Module: Filterable::Datable
- Defined in:
- lib/filterable/datable.rb,
lib/filterable/datable/after.rb,
lib/filterable/datable/range.rb,
lib/filterable/datable/since.rb,
lib/filterable/datable/before.rb
Overview
Namespace for the date filters and the helpers they share.
Defined Under Namespace
Modules: After, Before, Range, Since
Class Method Summary collapse
-
.columns(params, scope) ⇒ Hash{Symbol, String => Hash}
private
Whitelist the params to the declared datable attributes and resolve each one to its DB column, so a filter only ever touches columns the model opted in.
-
.parse(value) ⇒ Date, ...
private
Coerce a raw filter value into a Date/Time, or nil when it cannot be parsed, so a malformed query param narrows nothing instead of raising.
Class Method Details
.columns(params, scope) ⇒ Hash{Symbol, String => Hash}
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.
Whitelist the params to the declared datable attributes and resolve each one to its DB column, so a filter only ever touches columns the model opted in.
34 35 36 37 38 39 |
# File 'lib/filterable/datable.rb', line 34 def columns(params, scope) declared = scope.datable_attribute_names sliced = params.slice(*declared.keys) sliced = sliced.to_unsafe_h if sliced.respond_to?(:to_unsafe_h) sliced.transform_keys { |name| declared[name] } end |
.parse(value) ⇒ Date, ...
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.
Coerce a raw filter value into a Date/Time, or nil when it cannot be parsed, so a malformed query param narrows nothing instead of raising.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/filterable/datable.rb', line 14 def parse(value) case value when Date, Time value else begin Time.parse(value.to_s) rescue ArgumentError nil end end end |