searchable: refactor search_boolean_attribute.
This commit is contained in:
@@ -102,16 +102,11 @@ module Searchable
|
|||||||
where_operator(qualified_column, *range)
|
where_operator(qualified_column, *range)
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_boolean_attribute(attribute, params)
|
def search_boolean_attribute(attr, params)
|
||||||
return all unless params.key?(attribute)
|
if params[attr].present?
|
||||||
|
boolean_attribute_matches(attr, params[attr])
|
||||||
value = params[attribute].to_s
|
|
||||||
if value.truthy?
|
|
||||||
where(attribute => true)
|
|
||||||
elsif value.falsy?
|
|
||||||
where(attribute => false)
|
|
||||||
else
|
else
|
||||||
raise ArgumentError, "value must be truthy or falsy"
|
all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -133,6 +128,18 @@ module Searchable
|
|||||||
where_operator(qualified_column, *range)
|
where_operator(qualified_column, *range)
|
||||||
end
|
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")
|
def text_attribute_matches(attribute, value, index_column: nil, ts_config: "english")
|
||||||
return all unless value.present?
|
return all unless value.present?
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user