Sha256: 3901008be7a71d991fcd9d28eaee319b636318e66c69d98c43577cea45f44f04

Contents?: true

Size: 582 Bytes

Versions: 3

Compression:

Stored size: 582 Bytes

Contents

module Arel
  class Order < Compound
    attr_reader :orderings

    def initialize(relation, orderings)
      super(relation)
      @orderings = orderings.collect { |o| o.bind(relation) }
    end

    # TESTME
    def orders
      # QUESTION - do we still need relation.orders ?
      (orderings + relation.orders).collect { |o| o.bind(self) }.collect { |o| o.to_ordering }
    end

    def eval
      unoperated_rows.sort do |row1, row2|
        ordering = orders.detect { |o| o.eval(row1, row2) != 0 } || orders.last
        ordering.eval(row1, row2)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
arel-1.0.1 lib/arel/algebra/relations/operations/order.rb
arel-1.0.0 lib/arel/algebra/relations/operations/order.rb
arel-1.0.0.rc1 lib/arel/algebra/relations/operations/order.rb