Sha256: b04f2dfcdcb9b7925de84387cfff67ee322354ebfc874f5021af24eb5f2463bf

Contents?: true

Size: 558 Bytes

Versions: 3

Compression:

Stored size: 558 Bytes

Contents

module RecordFilter
  class Order
    attr_reader :column, :direction, :table

    def initialize(column, direction, table)
      @column, @direction, @table = column, direction, table
    end

    def to_sql
      dir = case @direction
        when :asc then 'ASC'
        when :desc then 'DESC'
      end
      
      table, column = @table, @column
      while column.is_a?(Hash)
        table = table.join_association(column.keys[0]).right_table
        column = column.values[0]
      end

      "#{table.table_name}.#{column} #{dir}"
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
aub-record_filter-0.1.0 lib/record_filter/order.rb
aub-record_filter-0.1.1 lib/record_filter/order.rb
outoftime-record_filter-0.1.0 lib/record_filter/order.rb