Module: Card::LookupQuery::Filtering
- Included in:
- Card::LookupQuery
- Defined in:
- lib/card/lookup_query/filtering.rb
Overview
shared filtering methods for query classes built on lookup tables
Instance Method Summary collapse
- #filter_by_not_ids(value) ⇒ Object
- #filter_card_id(key, value) ⇒ Object
- #filter_exact_match(key, value) ⇒ Object
- #filter_method(key) ⇒ Object
- #normalize_filter_args ⇒ Object
- #process_filter_option(key, value) ⇒ Object
- #process_filters ⇒ Object
Instance Method Details
#filter_by_not_ids(value) ⇒ Object
43 44 45 46 |
# File 'lib/card/lookup_query/filtering.rb', line 43 def filter_by_not_ids value add_condition "#{lookup_class.card_column} not in (?)", not_ids_value(value) end |
#filter_card_id(key, value) ⇒ Object
37 38 39 40 41 |
# File 'lib/card/lookup_query/filtering.rb', line 37 def filter_card_id key, value return unless (card_id = to_card_id value) filter card_id_map[key], card_id end |
#filter_exact_match(key, value) ⇒ Object
33 34 35 |
# File 'lib/card/lookup_query/filtering.rb', line 33 def filter_exact_match key, value filter key, value if value.present? end |
#filter_method(key) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/card/lookup_query/filtering.rb', line 24 def filter_method key case key when *simple_filters :filter_exact_match when *card_id_filters :filter_card_id end end |
#normalize_filter_args ⇒ Object
12 13 14 |
# File 'lib/card/lookup_query/filtering.rb', line 12 def normalize_filter_args # override end |
#process_filter_option(key, value) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/card/lookup_query/filtering.rb', line 16 def process_filter_option key, value if (method = filter_method key) send method, key, value else try "filter_by_#{key}", value end end |
#process_filters ⇒ Object
5 6 7 8 9 10 |
# File 'lib/card/lookup_query/filtering.rb', line 5 def process_filters normalize_filter_args return if @empty_result @filter_args.each { |k, v| process_filter_option k, v if v.present? } @restrict_to_ids.each { |k, v| filter k, v } end |