class Thorderbolt::OrderQueryBuilder

Builds full query for performing custom ordering

Protected Instance Methods

build_case_else(when_queries) click to toggle source

result example: CASE

WHEN 'cities'.'name'='City 1' THEN 0
WHEN 'cities'.'name'='City 5' THEN 1
ELSE 2

END

# File lib/thorderbolt/order_query_builder.rb, line 29
def build_case_else(when_queries)
  "CASE #{when_queries.join(' ')} ELSE #{when_queries.size} END"
end
build_when_then_part(conditions) click to toggle source

result example: WHEN 'cities'.'name'='City 1' THEN 0

# File lib/thorderbolt/order_query_builder.rb, line 17
def build_when_then_part(conditions)
  conditions.map.with_index do |condition, index|
    "WHEN #{condition} THEN #{index}"
  end
end