Class: Searchlight::Search

Inherits:
Object
  • Object
show all
Extended by:
DSL
Defined in:
lib/searchlight/search.rb

Defined Under Namespace

Classes: UndefinedOption

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DSL

search_on, searches

Constructor Details

#initialize(options = {}) ⇒ Search

Returns a new instance of Search.



11
12
13
# File 'lib/searchlight/search.rb', line 11

def initialize(options = {})
  filter_and_mass_assign(options)
end

Instance Attribute Details

#searchObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/searchlight/search.rb', line 15

def search
  @search ||= begin
                target = self.class.search_target
                if callable?(target)
                  # for delayed scope evaluation
                  target.call
                else
                  target
                end
              end
end

Class Method Details

.search_targetObject



5
6
7
8
9
# File 'lib/searchlight/search.rb', line 5

def self.search_target
  return @search_target           if defined?(@search_target)
  return superclass.search_target if superclass.respond_to?(:search_target) && superclass != Searchlight::Search
  guess_search_class!
end

Instance Method Details

#optionsObject



31
32
33
34
35
36
# File 'lib/searchlight/search.rb', line 31

def options
  search_attributes.reduce({}) { |hash, option_name|
    option_val = send(option_name)
    hash.tap { |hash| hash[option_name.to_sym] = option_val unless is_blank?(option_val) }
  }
end

#resultsObject



27
28
29
# File 'lib/searchlight/search.rb', line 27

def results
  @results ||= run
end