~ubuntu-branches/debian/sid/ruby-batch-loader/sid

« back to all changes in this revision

Viewing changes to lib/batch_loader/executor.rb

  • Committer: Package Import Robot
  • Author(s): Pirate Praveen
  • Date: 2018-03-17 13:06:55 UTC
  • Revision ID: package-import@ubuntu.com-20180317130655-v1v5wubhc5zxb3zt
Tags: upstream-1.2.1
ImportĀ upstreamĀ versionĀ 1.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# frozen_string_literal: true
 
2
 
 
3
class BatchLoader
 
4
  class Executor
 
5
    NAMESPACE = :batch_loader
 
6
 
 
7
    def self.ensure_current
 
8
      Thread.current[NAMESPACE] ||= new
 
9
    end
 
10
 
 
11
    def self.current
 
12
      Thread.current[NAMESPACE]
 
13
    end
 
14
 
 
15
    def self.clear_current
 
16
      Thread.current[NAMESPACE] = nil
 
17
    end
 
18
 
 
19
    attr_reader :items_by_block, :loaded_values_by_block
 
20
 
 
21
    def initialize
 
22
      @items_by_block = Hash.new { |hash, key| hash[key] = Set.new }
 
23
      @loaded_values_by_block = Hash.new { |hash, key| hash[key] = {} }
 
24
    end
 
25
  end
 
26
end