Sha256: f87d74c70455913e074ba8bac606e0ce139841aeb4acf16d881fb4a9c72c3eaa

Contents?: true

Size: 674 Bytes

Versions: 3

Compression:

Stored size: 674 Bytes

Contents

module RecordFilter
  class Order # :nodoc: all
    include ColumnParser

    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, 'asc' then 'ASC'
        when :desc, 'desc' then 'DESC'
        else raise InvalidFilterException.new("An invalid order of #{@direction} was specified.") 
      end

      column, table = parse_column_in_table(@column, @table)

      if (table.has_column(column))
        "#{table.table_alias}.#{column} #{dir}"
      else
        "#{column} #{dir}"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
record_filter-1.0.1 lib/record_filter/order.rb
record_filter-1.0.0 lib/record_filter/order.rb
record_filter-0.9.17 lib/record_filter/order.rb