Class: RequestContext
- Inherits:
-
Object
- Object
- RequestContext
- Defined in:
- backend/app/lib/request_context.rb
Class Method Summary collapse
-
.active? ⇒ Boolean
-
.dump ⇒ Object
-
.get(key) ⇒ Object
-
.in_global_repo ⇒ Object
-
.open(context = {}) ⇒ Object
-
.put(key, val) ⇒ Object
Class Method Details
.active? ⇒ Boolean
3 4 5 |
# File 'backend/app/lib/request_context.rb', line 3 def self.active? !Thread.current[:request_context].nil? end |
.dump ⇒ Object
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_repo ⇒ Object
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 |