Class: CrazyTrain::QueryBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/models/crazy_train/query_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#klassObject (readonly)

Returns the value of attribute klass.



3
4
5
# File 'app/models/crazy_train/query_builder.rb', line 3

def klass
  @klass
end

#ordersObject (readonly)

Returns the value of attribute orders.



3
4
5
# File 'app/models/crazy_train/query_builder.rb', line 3

def orders
  @orders
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'app/models/crazy_train/query_builder.rb', line 3

def params
  @params
end

#queryObject (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