Sha256: a84bfa683ad2308e0fe07b2ca6344d41f416abb0c37538b47a3b7b6afb2bdffb

Contents?: true

Size: 725 Bytes

Versions: 6

Compression:

Stored size: 725 Bytes

Contents

module RecordFilter
  class Order # :nodoc: all
    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

      if (!table.has_column(column))
        raise ColumnNotFoundException.new("The column #{column} was not found in #{table.table_name}.")
      end

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

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
aub-record_filter-0.8.0 lib/record_filter/order.rb
aub-record_filter-0.9.0 lib/record_filter/order.rb
aub-record_filter-0.9.1 lib/record_filter/order.rb
aub-record_filter-0.9.2 lib/record_filter/order.rb
aub-record_filter-0.9.3 lib/record_filter/order.rb
outoftime-record_filter-0.8.0 lib/record_filter/order.rb