aboutsummaryrefslogblamecommitdiffstats
path: root/lib/arel/session.rb
blob: f6016431c3b744aec635af062a0312a7b1e61f55 (plain) (tree)
1
2
3
4
5
6
7
8
           
               

                   


                      
 




                       
       
 


                      
 





                                         
 


                      
 

                      
       
     
   
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