aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/relations/operations/take.rb
blob: 7098d578d5def32e2332b52f8236fd6444397573 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module Arel
  class Take < Compound
    attr_reader :taken

    def initialize relation, taken
      super(relation)
      @taken = taken
    end

    def == other
      super ||
        Take === other &&
        relation == other.relation &&
        taken == other.taken
    end

    def engine
      engine   = relation.engine

      # Temporary check of whether or not the engine supports where.
      if engine.respond_to?(:supports) && !engine.supports(:limiting)
        Memory::Engine.new
      else
        engine
      end
    end

    def externalizable?
      true
    end

    def eval
      unoperated_rows[0, taken]
    end
  end
end