Module: Searcher::ClassMethods

Defined in:
lib/searcher/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#search(query) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/searcher/class_methods.rb', line 10

def search(query)
  klass = self

  result = query.split(" ").inject(klass) do |k, piece|
    if piece.include?(":")
      name, q = piece.split(":")
      label = @config[:labels][name.to_sym]
      next unless label
      send("by_#{name}", q, label[:field])
    end
  end
  
  result || klass.all
end

#searcher(&block) ⇒ Object



5
6
7
8
# File 'lib/searcher/class_methods.rb', line 5

def searcher(&block)
  Searcher.classes << self unless Searcher.classes.include?(self)
  @config ||= Searcher::Config.new.instance_exec(&block)
end