debian-mirror-gitlab/app/models/concerns/optionally_search.rb

20 lines
462 B
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
module OptionallySearch
extend ActiveSupport::Concern
class_methods do
2020-04-22 19:07:51 +05:30
def search(query, **options)
2018-11-20 20:47:30 +05:30
raise(
NotImplementedError,
'Your model must implement the "search" class method'
)
end
# Optionally limits a result set to those matching the given search query.
2020-04-22 19:07:51 +05:30
def optionally_search(query = nil, **options)
query.present? ? search(query, **options) : all
2018-11-20 20:47:30 +05:30
end
end
end