1# frozen_string_literal: true
2
3module OptionallySearch
4  extend ActiveSupport::Concern
5
6  class_methods do
7    def search(query, **options)
8      raise(
9        NotImplementedError,
10        'Your model must implement the "search" class method'
11      )
12    end
13
14    # Optionally limits a result set to those matching the given search query.
15    def optionally_search(query = nil, **options)
16      query.present? ? search(query, **options) : all
17    end
18  end
19end
20