def search_param_datetime(query: nil, attribute_key: nil, attribute_array: [])
fail 'Must have a valid query' if query.nil?
fail 'Must have a valid attribute key' if attribute_key.nil?
logger.debug "[Search param DateTime] Searching #{attribute_key} -> #{attribute_array.to_json}"
if attribute_array.nil? || attribute_array.empty?
logger.debug "[Search param DateTime] Backing out of filter - no values exist for #{attribute_key}"
return query
end
attribute_array.each do |attrs|
attrs.each do |attr|
attr = attr.to_a.flatten
logger.debug "[Search param DateTime] Filtering by #{attribute_key} #{attr.first} #{attr.last}"
case attr.first
when 'before'
query = query.where(query.model.arel_table[attribute_key.to_sym].lt(attr.last))
when 'after'
query = query.where(query.model.arel_table[attribute_key.to_sym].gt(attr.last))
when 'on'
query = query.where(attribute_key => (attr.last..attr.last.end_of_day))
end
end
end
@queries += 1
query
end