Sha256: bc22a21d3c02aed314805150bba68a3d6be7612db244ee98109ad01033afa127
Contents?: true
Size: 745 Bytes
Versions: 2
Compression:
Stored size: 745 Bytes
Contents
module JsonApiFilter module FieldFilters class Matcher < Base # @return [ActiveRecord_Relation] def predicate values.map do |key, value| scope.where( key_translation(key) => ::JsonApiFilter::ValueParser.parse(value) ) end.reduce(&:merge) end private #TODO: move to another class def key_translation(key) return key unless association table_name(key) end # @return [ActiveRecord::Base] def model_klass scope.try(:klass) || scope end def table_name(association_name) model_klass.reflections[association_name.to_s].table_name end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
json_api_filter-0.3.2 | lib/json_api_filter/field_filters/matcher.rb |
json_api_filter-0.2 | lib/json_api_filter/field_filters/matcher.rb |