Class: CrazyTrain::QueryBuilder
- Inherits:
-
Object
- Object
- CrazyTrain::QueryBuilder
- Defined in:
- app/models/crazy_train/query_builder.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#orders ⇒ Object
readonly
Returns the value of attribute orders.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
-
#initialize(klass, params) ⇒ QueryBuilder
constructor
A new instance of QueryBuilder.
- #parse! ⇒ Object
Constructor Details
#initialize(klass, params) ⇒ QueryBuilder
Returns a new instance of QueryBuilder.
5 6 7 8 9 10 |
# File 'app/models/crazy_train/query_builder.rb', line 5 def initialize(klass, params) @klass = klass @params = params @query = nil @orders = [] end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
3 4 5 |
# File 'app/models/crazy_train/query_builder.rb', line 3 def klass @klass end |
#orders ⇒ Object (readonly)
Returns the value of attribute orders.
3 4 5 |
# File 'app/models/crazy_train/query_builder.rb', line 3 def orders @orders end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'app/models/crazy_train/query_builder.rb', line 3 def params @params end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
3 4 5 |
# File 'app/models/crazy_train/query_builder.rb', line 3 def query @query end |
Instance Method Details
#parse! ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/crazy_train/query_builder.rb', line 12 def parse! @query = klass.all return unless params[:order] @order_parser = CrazyTrain::OrderParser.new(params[:order]) @order_parser.parse! @orders = @order_parser.orders @query = @query.order(@orders) # if params[:select] # end end |