Class: SearchCop::QueryBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/search_cop/query_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, query, scope, query_options) ⇒ QueryBuilder

Returns a new instance of QueryBuilder.



5
6
7
8
9
10
11
12
# File 'lib/search_cop/query_builder.rb', line 5

def initialize(model, query, scope, query_options)
  self.scope = scope
  self.query_info = QueryInfo.new(model, scope)

  arel = SearchCop::Parser.parse(query, query_info, query_options).optimize!

  self.sql = SearchCop::Visitors::Visitor.new(model.connection).visit(arel)
end

Instance Attribute Details

#query_infoObject

Returns the value of attribute query_info.



3
4
5
# File 'lib/search_cop/query_builder.rb', line 3

def query_info
  @query_info
end

#scopeObject

Returns the value of attribute scope.



3
4
5
# File 'lib/search_cop/query_builder.rb', line 3

def scope
  @scope
end

#sqlObject

Returns the value of attribute sql.



3
4
5
# File 'lib/search_cop/query_builder.rb', line 3

def sql
  @sql
end

Instance Method Details

#associationsObject



14
15
16
# File 'lib/search_cop/query_builder.rb', line 14

def associations
  all_associations - [query_info.model.name.tableize.to_sym]
end