Class: JsonApiFilter::FieldFilters::Compare
- Defined in:
- lib/json_api_filter/field_filters/compare.rb
Instance Attribute Summary collapse
-
#allowed_searches ⇒ Object
readonly
Returns the value of attribute allowed_searches.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(scope, values, allowed_searches:) ⇒ Compare
constructor
A new instance of Compare.
- #predicate ⇒ ActiveRecord_Relation
Constructor Details
#initialize(scope, values, allowed_searches:) ⇒ Compare
Returns a new instance of Compare.
8 9 10 11 |
# File 'lib/json_api_filter/field_filters/compare.rb', line 8 def initialize(scope, values, allowed_searches:) super(scope, values) @allowed_searches = allowed_searches end |
Instance Attribute Details
#allowed_searches ⇒ Object (readonly)
Returns the value of attribute allowed_searches.
6 7 8 |
# File 'lib/json_api_filter/field_filters/compare.rb', line 6 def allowed_searches @allowed_searches end |
Instance Method Details
#predicate ⇒ ActiveRecord_Relation
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/json_api_filter/field_filters/compare.rb', line 14 def predicate column = values.keys.first filter = values.first[1] filter.map do |key, value| if !WHERE_METHODS[key.to_sym].nil? compare(column, key, value) elsif key == "search" next unless allowed_searches[:columns].keys.include?(column.to_sym) ::JsonApiFilter::FieldFilters::Searcher.new( scope, {allowed_searches[:columns][column.to_sym] => value} ).predicate else nil end end.compact.reduce(&:merge) end |