Class: Segugio::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/segugio/search.rb

Overview

Implements a feature for generic search, that allows to search using ILIKE operator, filter records by exact value and specify result order.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relation, options = {}) ⇒ Search

Returns a new instance of Search.



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

def initialize(relation, options = {})
  @relation = relation
  options = options.to_h.with_indifferent_access
  @configs = options[:configs] || {}
  @options = options

  parse_options

  @result = relation.all

  configure!
  generate_search_result!
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



9
10
11
# File 'lib/segugio/search.rb', line 9

def result
  @result
end

Instance Method Details

#collection_nameObject



25
26
27
# File 'lib/segugio/search.rb', line 25

def collection_name
  @collection_name ||= @relation.model_name.collection.split('/').last
end

#loggerObject



29
30
31
# File 'lib/segugio/search.rb', line 29

def logger
  @logger ||= ActiveRecord::Base.logger
end