Module: NameSearch::NameSearchOn

Defined in:
lib/name_search/name_search_on.rb

Instance Method Summary collapse

Instance Method Details

#name_search(name, options = {}) ⇒ Object



4
5
6
# File 'lib/name_search/name_search_on.rb', line 4

def name_search(name, options = {})
  NameSearch::Search.new(self, name, options)
end

#name_search_on(*attributes) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/name_search/name_search_on.rb', line 3

def name_search_on(*attributes)
  def name_search(name, options = {})
    NameSearch::Search.new(self, name, options)
  end

  class_eval do
    include NameSearchablesConcerns
    class_attribute :name_search_attributes
    self.name_search_attributes = attributes

    after_save :sync_name_searchables
    has_many :name_searchables, -> { includes :name }, as: :searchable,
      dependent: :destroy, class_name: 'NameSearch::Searchable'
  end
end