Class: Quickfilter::QueryBuilder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, adapter = nil) ⇒ QueryBuilder

Returns a new instance of QueryBuilder.



7
8
9
10
11
12
13
14
# File 'lib/quickfilter/query_builder.rb', line 7

def initialize(klass, adapter=nil)
  @klass = klass
  @query = klass.where(nil)
  @associations = klass.reflect_on_all_associations

  @adapter = adapter
  @adapter ||= ActiveRecord::Base.connection_config[:adapter]
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



5
6
7
# File 'lib/quickfilter/query_builder.rb', line 5

def adapter
  @adapter
end

#klassObject (readonly)

Returns the value of attribute klass.



5
6
7
# File 'lib/quickfilter/query_builder.rb', line 5

def klass
  @klass
end

#queryObject (readonly)

Returns the value of attribute query.



5
6
7
# File 'lib/quickfilter/query_builder.rb', line 5

def query
  @query
end

Instance Method Details

#build(params) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/quickfilter/query_builder.rb', line 16

def build(params)
  params.each do |param|
    self.with(param) do |tablename, fieldname, operator, value|
      self.filter(tablename, fieldname, operator, value)
      self.join(tablename) if tablename != @klass.table_name
    end
  end
  return self
end