Class: RequestContext

Inherits:
Object
  • Object
show all
Defined in:
backend/app/lib/request_context.rb

Class Method Summary collapse

Class Method Details

.active?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'backend/app/lib/request_context.rb', line 3

def self.active?
  !Thread.current[:request_context].nil?
end

.dumpObject



44
45
46
# File 'backend/app/lib/request_context.rb', line 44

def self.dump
  Thread.current[:request_context].clone
end

.get(key) ⇒ Object



37
38
39
40
41
# File 'backend/app/lib/request_context.rb', line 37

def self.get(key)
  if Thread.current[:request_context]
    Thread.current[:request_context][key]
  end
end

.in_global_repoObject



8
9
10
11
12
# File 'backend/app/lib/request_context.rb', line 8

def self.in_global_repo
  self.open(:repo_id => Repository.global_repo_id) do
    yield
  end
end

.open(context = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'backend/app/lib/request_context.rb', line 15

def self.open(context = {})
  # Stash the original context
  original_context = Thread.current[:request_context]

  # Add in the bits we care about
  Thread.current[:request_context] ||= {}
  Thread.current[:request_context] = Thread.current[:request_context].merge(context)

  begin
    yield
  ensure
    # And restore the old context once done
    Thread.current[:request_context] = original_context
  end
end

.put(key, val) ⇒ Object



32
33
34
# File 'backend/app/lib/request_context.rb', line 32

def self.put(key, val)
  Thread.current[:request_context][key] = val
end