Module: WithScopedQueries::Filter
- Defined in:
- app/models/concerns/with_scoped_queries/filter.rb
Class Method Summary collapse
- .add_queriable_attributes_to(klass, attributes) ⇒ Object
- .query_by(params, current_scope, _) ⇒ Object
Class Method Details
.add_queriable_attributes_to(klass, attributes) ⇒ Object
12 13 14 |
# File 'app/models/concerns/with_scoped_queries/filter.rb', line 12 def self.add_queriable_attributes_to(klass, attributes) klass.queriable_attributes.merge!(filter: attributes) end |
.query_by(params, current_scope, _) ⇒ Object
2 3 4 5 6 7 8 9 10 |
# File 'app/models/concerns/with_scoped_queries/filter.rb', line 2 def self.query_by(params, current_scope, _) params.to_h.inject(current_scope) do |scope, (field, value)| if value.present? scope.public_send("by_#{field}", value) else scope end end end |