Class: Care::AutoFinder::Searcher

Inherits:
Object
  • Object
show all
Defined in:
lib/care/auto_finder/searcher.rb

Defined Under Namespace

Classes: ArtificalRelation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_tableObject (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

#attributesObject (readonly)

Returns the value of attribute attributes.



8
9
10
# File 'lib/care/auto_finder/searcher.rb', line 8

def attributes
  @attributes
end

#columnsObject (readonly)

Returns the value of attribute columns.



7
8
9
# File 'lib/care/auto_finder/searcher.rb', line 7

def columns
  @columns
end

#patternObject (readonly)

Returns the value of attribute pattern.



11
12
13
# File 'lib/care/auto_finder/searcher.rb', line 11

def pattern
  @pattern
end

#queryObject (readonly)

Returns the value of attribute query.



6
7
8
# File 'lib/care/auto_finder/searcher.rb', line 6

def query
  @query
end

#relationObject (readonly)

Returns the value of attribute relation.



5
6
7
# File 'lib/care/auto_finder/searcher.rb', line 5

def relation
  @relation
end

#tableObject (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

#callObject



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