debian-mirror-gitlab/app/models/concerns/optionally_search.rb
2018-11-20 20:47:30 +05:30

19 lines
425 B
Ruby

# frozen_string_literal: true
module OptionallySearch
extend ActiveSupport::Concern
class_methods do
def search(*)
raise(
NotImplementedError,
'Your model must implement the "search" class method'
)
end
# Optionally limits a result set to those matching the given search query.
def optionally_search(query = nil)
query.present? ? search(query) : all
end
end
end