aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/relations/operations/take.rb
blob: 421051124c90cc0912bd952e93c0a0e1dc4ae5bf (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
module Arel
  class Take < Compound
    attr_reader :taken

    def initialize relation, taken
      super(relation)
      @taken = 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