2018-07-30 11:45:49 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module OptionallySearch
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2018-08-27 08:35:31 -04:00
|
|
|
class_methods do
|
2020-03-24 11:08:44 -04:00
|
|
|
def search(query, **options)
|
2018-07-30 11:45:49 -04:00
|
|
|
raise(
|
|
|
|
NotImplementedError,
|
|
|
|
'Your model must implement the "search" class method'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Optionally limits a result set to those matching the given search query.
|
2020-03-23 08:09:47 -04:00
|
|
|
def optionally_search(query = nil, **options)
|
|
|
|
query.present? ? search(query, **options) : all
|
2018-07-30 11:45:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|