Class: Nexter::Query
- Inherits:
-
Object
- Object
- Nexter::Query
- Defined in:
- lib/nexter/query.rb,
lib/nexter/query/section.rb,
lib/nexter/query/direction.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#compass ⇒ Object
readonly
Returns the value of attribute compass.
-
#reorders ⇒ Object
readonly
Returns the value of attribute reorders.
-
#wheres ⇒ Object
readonly
Returns the value of attribute wheres.
Instance Method Summary collapse
-
#initialize(columns, goto) ⇒ Query
constructor
A new instance of Query.
- #iterate ⇒ Object (also: #sql)
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
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
3 4 5 |
# File 'lib/nexter/query.rb', line 3 def columns @columns end |
#compass ⇒ Object (readonly)
Returns the value of attribute compass.
3 4 5 |
# File 'lib/nexter/query.rb', line 3 def compass @compass end |
#reorders ⇒ Object (readonly)
Returns the value of attribute reorders.
3 4 5 |
# File 'lib/nexter/query.rb', line 3 def reorders @reorders end |
#wheres ⇒ Object (readonly)
Returns the value of attribute wheres.
3 4 5 |
# File 'lib/nexter/query.rb', line 3 def wheres @wheres end |
Instance Method Details
#iterate ⇒ Object 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 |