Class: Thorderbolt::BaseQueryBuilder
- Inherits:
-
Object
- Object
- Thorderbolt::BaseQueryBuilder
- Defined in:
- lib/thorderbolt/base_query_builder.rb
Overview
Builds full query for performing custom ordering
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
-
#build ⇒ Object
result example: CASE WHEN ‘cities’.‘name’=‘City 1’ THEN 0 WHEN ‘cities’.‘name’=‘City 5’ THEN 1 ELSE 2 END ASC.
-
#initialize(table_name:, attribute:, values:) ⇒ BaseQueryBuilder
constructor
A new instance of BaseQueryBuilder.
Constructor Details
#initialize(table_name:, attribute:, values:) ⇒ BaseQueryBuilder
Returns a new instance of BaseQueryBuilder.
8 9 10 11 12 |
# File 'lib/thorderbolt/base_query_builder.rb', line 8 def initialize(table_name:, attribute:, values:) @table_name = table_name @attribute = attribute @values = values end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
6 7 8 |
# File 'lib/thorderbolt/base_query_builder.rb', line 6 def attribute @attribute end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
6 7 8 |
# File 'lib/thorderbolt/base_query_builder.rb', line 6 def table_name @table_name end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
6 7 8 |
# File 'lib/thorderbolt/base_query_builder.rb', line 6 def values @values end |
Instance Method Details
#build ⇒ Object
result example: CASE
WHEN 'cities'.'name'='City 1' THEN 0
WHEN 'cities'.'name'='City 5' THEN 1
ELSE 2
END ASC
20 21 22 23 24 25 |
# File 'lib/thorderbolt/base_query_builder.rb', line 20 def build conditions = build_conditions when_queries = build_when_then_part(conditions) case_query = build_case_else(when_queries) Arel.sql("#{case_query} ASC") end |