Class: Care::AutoFinder::Searcher
- Inherits:
-
Object
- Object
- Care::AutoFinder::Searcher
- Defined in:
- lib/care/auto_finder/searcher.rb
Defined Under Namespace
Classes: ArtificalRelation
Instance Attribute Summary collapse
-
#arel_table ⇒ Object
readonly
Returns the value of attribute arel_table.
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#relation ⇒ Object
readonly
Returns the value of attribute relation.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(params) ⇒ Searcher
constructor
A new instance of Searcher.
Constructor Details
#initialize(params) ⇒ Searcher
Returns a new instance of Searcher.
13 14 15 16 17 18 19 20 21 |
# File 'lib/care/auto_finder/searcher.rb', line 13 def initialize(params) @relation = params[:items] @columns = params[:columns] @attributes = params[:columns] @query = params[:search] @arel_table = relation.arel_table @table = relation.arel_table @pattern = "%#{sanitaze(query)}%" end |
Instance Attribute Details
#arel_table ⇒ Object (readonly)
Returns the value of attribute arel_table.
9 10 11 |
# File 'lib/care/auto_finder/searcher.rb', line 9 def arel_table @arel_table end |
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/care/auto_finder/searcher.rb', line 8 def attributes @attributes end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
7 8 9 |
# File 'lib/care/auto_finder/searcher.rb', line 7 def columns @columns end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
11 12 13 |
# File 'lib/care/auto_finder/searcher.rb', line 11 def pattern @pattern end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
6 7 8 |
# File 'lib/care/auto_finder/searcher.rb', line 6 def query @query end |
#relation ⇒ Object (readonly)
Returns the value of attribute relation.
5 6 7 |
# File 'lib/care/auto_finder/searcher.rb', line 5 def relation @relation end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
10 11 12 |
# File 'lib/care/auto_finder/searcher.rb', line 10 def table @table end |
Class Method Details
.call(params) ⇒ Object
23 24 25 |
# File 'lib/care/auto_finder/searcher.rb', line 23 def self.call(params) new(params).call end |
Instance Method Details
#call ⇒ Object
27 28 29 30 |
# File 'lib/care/auto_finder/searcher.rb', line 27 def call predicate = complile_node(relation, attributes).reduce { |memo, expression| memo ? memo.or(expression) : memo } relation.where(predicate) end |