Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to apply Custom Operators or Options to entire project #68

Closed
westonganger opened this issue Apr 22, 2022 · 1 comment
Closed

Comments

@westonganger
Copy link

westonganger commented Apr 22, 2022

Is is possible to add Custom Operators or Options to every search in the entire project?

For example

# config/initializers/search_cop.rb

SearchCop.defaults do

  generator :like_string do |column_name, raw_value|
    pattern = quote("%#{raw_value}%")
    "#{column_name} LIKE #{pattern}"
  end

  options :all, :type => :fulltext, default: true

end

Since its probably 2 seperate works to add generators and options. Its of a much higher importance to add this functionality for the generators

@mrkamel
Copy link
Owner

mrkamel commented Apr 27, 2022

it's not possible like you specified it. But i think something like the following can be used to achieve something similar:

def with_search_defaults(scope)
  scope.generator ...
end

search_scope :search do
  with_search_defaults(self)

  ...
end

or even

module SearchGenerators
  def self.extended(scope)
    scope.generator ...
  end
end

search_scope :search do
  extend SearchGenerators
end

@mrkamel mrkamel closed this as completed Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants