aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/session.rb
blob: f6016431c3b744aec635af062a0312a7b1e61f55 (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
module Arel
  class Session
    @instance = nil

    def self.instance
      @instance || new
    end

    def self.start
      @instance ||= new
      yield @instance
    ensure
      @instance = nil
    end

    def create(insert)
      insert.call
    end

    def read(select)
      @read ||= {}
      key = select.object_id
      return @read[key] if @read.key? key
      @read[key] = select.call
    end

    def update(update)
      update.call
    end

    def delete(delete)
      delete.call
    end
  end
end