searchable: refactor search_boolean_attribute.

This commit is contained in:
evazion
2020-12-27 05:26:21 -06:00
parent 4756141156
commit 7f1b798b05

View File

@@ -102,16 +102,11 @@ module Searchable
where_operator(qualified_column, *range)
end
def search_boolean_attribute(attribute, params)
return all unless params.key?(attribute)
value = params[attribute].to_s
if value.truthy?
where(attribute => true)
elsif value.falsy?
where(attribute => false)
def search_boolean_attribute(attr, params)
if params[attr].present?
boolean_attribute_matches(attr, params[attr])
else
raise ArgumentError, "value must be truthy or falsy"
all
end
end
@@ -133,6 +128,18 @@ module Searchable
where_operator(qualified_column, *range)
end
def boolean_attribute_matches(attribute, value)
value = value.to_s
if value.truthy?
where(attribute => true)
elsif value.falsy?
where(attribute => false)
else
raise ArgumentError, "value must be truthy or falsy"
end
end
def text_attribute_matches(attribute, value, index_column: nil, ts_config: "english")
return all unless value.present?