Class: Nexter::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/nexter/query.rb,
lib/nexter/query/section.rb,
lib/nexter/query/direction.rb

Defined Under Namespace

Classes: Direction, Section

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(columns, goto) ⇒ Query

Returns a new instance of Query.



5
6
7
8
9
10
# File 'lib/nexter/query.rb', line 5

def initialize(columns, goto)
  @columns = columns
  @compass = Compass.new(goto)
  @reorders = []
  iterate
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



3
4
5
# File 'lib/nexter/query.rb', line 3

def columns
  @columns
end

#compassObject (readonly)

Returns the value of attribute compass.



3
4
5
# File 'lib/nexter/query.rb', line 3

def compass
  @compass
end

#reordersObject (readonly)

Returns the value of attribute reorders.



3
4
5
# File 'lib/nexter/query.rb', line 3

def reorders
  @reorders
end

#wheresObject (readonly)

Returns the value of attribute wheres.



3
4
5
# File 'lib/nexter/query.rb', line 3

def wheres
  @wheres
end

Instance Method Details

#iterateObject Also known as: sql



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/nexter/query.rb', line 12

def iterate
  @wheres = []
  columns = @columns.dup

  while column = columns.pop do
    section   = Section.new(columns)
    direction = Direction.new(column, compass)

    reorders.unshift("#{column[:col]} #{direction.compass.redirection}")

    next unless direction.slice

    @wheres << "#{section.sql}#{section.blank? ? '' : ' AND '}#{direction.sql}"
  end

  # binding.pry
  @wheres.compact!
end