Class: Oversee::Filter
- Inherits:
-
Object
- Object
- Oversee::Filter
- Defined in:
- app/service/oversee/filter.rb
Constant Summary collapse
- ALLOWED_OPERATORS =
%w[eq in gt gte lt lte].freeze
Instance Method Summary collapse
- #apply ⇒ Object
-
#initialize(collection:, params: nil) ⇒ Filter
constructor
A new instance of Filter.
Constructor Details
#initialize(collection:, params: nil) ⇒ Filter
Returns a new instance of Filter.
4 5 6 7 |
# File 'app/service/oversee/filter.rb', line 4 def initialize(collection:, params: nil) @collection = collection @params = params end |
Instance Method Details
#apply ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/service/oversee/filter.rb', line 10 def apply return @collection if filters.blank? filters.each do |key, constraint| operator = constraint.keys.first next unless ALLOWED_OPERATORS.include?(operator) value = constraint[operator] chain(key:, operator:, value:) end return @collection end |