Module: SnFoil::Searcher

Extended by:
ActiveSupport::Concern
Defined in:
lib/snfoil/searcher.rb,
lib/snfoil/searcher/boolean.rb,
lib/snfoil/searcher/version.rb

Overview

Author:

  • Matthew Howes

Since:

  • 0.1.0

Defined Under Namespace

Classes: ArgumentError, Boolean, Error

Constant Summary collapse

VERSION =

Since:

  • 0.1.0

'1.1.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#scopeObject (readonly)

Since:

  • 0.1.0



72
73
74
# File 'lib/snfoil/searcher.rb', line 72

def scope
  @scope
end

Instance Method Details

#booleansObject

Since:

  • 0.1.0



97
98
99
# File 'lib/snfoil/searcher.rb', line 97

def booleans
  self.class.snfoil_booleans || []
end

#filterObject

Since:

  • 0.1.0



87
# File 'lib/snfoil/searcher.rb', line 87

def filter; end

#filtersObject

Since:

  • 0.1.0



93
94
95
# File 'lib/snfoil/searcher.rb', line 93

def filters
  self.class.snfoil_filters || []
end

#initialize(scope: nil) ⇒ Object

Raises:

Since:

  • 0.1.0



74
75
76
77
78
# File 'lib/snfoil/searcher.rb', line 74

def initialize(scope: nil)
  raise SnFoil::Searcher::Error, "No default scope or model configured for #{self.class.name}" if !scope && !model

  @scope = scope || model.all
end

#modelObject

Since:

  • 0.1.0



68
69
70
# File 'lib/snfoil/searcher.rb', line 68

def model
  self.class.snfoil_model
end

#search(params = {}) ⇒ Object

Since:

  • 0.1.0



80
81
82
83
84
85
# File 'lib/snfoil/searcher.rb', line 80

def search(params = {})
  params = transform_params_booleans(params) # this is required for params coming in from http-like sources
  filtered_scope = filter || scope # start usimg the default scope of the class or the filter method
  filtered_scope = apply_setup(filtered_scope, params)
  apply_filters(filtered_scope, params)
end

#setupObject

Since:

  • 0.1.0



89
90
91
# File 'lib/snfoil/searcher.rb', line 89

def setup
  self.class.snfoil_setup
end