Module: JSONAPI::Resources::Filterer::ClassMethods
- Defined in:
- lib/jsonapi/resources/filterer.rb
Instance Method Summary collapse
- #apply_filter(records, filter, value, _options = {}) ⇒ Object
- #filterer(filterer_class) ⇒ Object
- #filterer_class ⇒ Object
Instance Method Details
#apply_filter(records, filter, value, _options = {}) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/jsonapi/resources/filterer.rb', line 37 def apply_filter(records, filter, value, = {}) if self._filterer self._filterer.filter({filter => value}, {starting_query: records}) else super(records, filter, value, = {}) end end |
#filterer(filterer_class) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jsonapi/resources/filterer.rb', line 23 def filterer(filterer_class) self._filterer = filterer_class if self._filterer method_names = self._filterer.instance_methods. grep(/^param_\w+/) filter_names = method_names.map do |m| m.to_s.sub("param_", "").to_sym end filter_names -= self._allowed_filters.keys filters(*filter_names) end end |
#filterer_class ⇒ Object
17 18 19 20 21 |
# File 'lib/jsonapi/resources/filterer.rb', line 17 def filterer_class class_name = self.name.demodulize.gsub("Resource", "Filterer") module_name = self.name.deconstantize filterer_class_from(module_name, class_name) end |