Class: Quickfilter::QueryBuilder
- Inherits:
-
Object
- Object
- Quickfilter::QueryBuilder
- Defined in:
- lib/quickfilter/query_builder.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
- #build(params) ⇒ Object
-
#initialize(klass, adapter = nil) ⇒ QueryBuilder
constructor
A new instance of QueryBuilder.
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
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
5 6 7 |
# File 'lib/quickfilter/query_builder.rb', line 5 def adapter @adapter end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
5 6 7 |
# File 'lib/quickfilter/query_builder.rb', line 5 def klass @klass end |
#query ⇒ Object (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 |