Class: Thorderbolt::RangeBuilder
- Inherits:
-
Object
- Object
- Thorderbolt::RangeBuilder
- Defined in:
- lib/thorderbolt/range_builder.rb
Overview
Builds a part of query for using a range as a sorting parameter
Class Method Summary collapse
Class Method Details
.build(table, column, range) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/thorderbolt/range_builder.rb', line 7 def build(table, column, range) full_column_name = "#{connection.quote_table_name(table)}"\ ".#{connection.quote_column_name(column)}" closing_condition = range.exclude_end? ? '<' : '<=' template = "#{full_column_name} >= :minimal "\ "AND #{full_column_name} #{closing_condition} :maximum" range_bounds = [range.begin, range.end] range_hash = { minimal: range_bounds.min, maximum: range_bounds.max } ActiveRecord::Base.sanitize_sql([template, range_hash]) end |