Class: Hey::ThreadCargo
- Inherits:
-
Object
- Object
- Hey::ThreadCargo
- Defined in:
- lib/hey/thread_cargo.rb
Class Method Summary collapse
-
.add_context(context) ⇒ Object
Sets a context on the current thread.
- .contexts ⇒ Object
- .init! ⇒ Object
- .init_contexts! ⇒ Object
-
.purge! ⇒ Object
Removes all namespaced values from the current thread.
-
.remove_context(context) ⇒ Object
Returns a context from the current thread.
- .uuid ⇒ Object
Class Method Details
.add_context(context) ⇒ Object
Sets a context on the current thread
18 19 20 21 |
# File 'lib/hey/thread_cargo.rb', line 18 def self.add_context(context) self.init_contexts! Thread.current[:hey][:contexts] << context end |
.contexts ⇒ Object
34 35 36 37 |
# File 'lib/hey/thread_cargo.rb', line 34 def self.contexts self.init_contexts! Thread.current[:hey][:contexts] end |
.init! ⇒ Object
2 3 4 5 |
# File 'lib/hey/thread_cargo.rb', line 2 def self.init! Thread.current[:hey] = {} if Thread.current[:hey].nil? Thread.current[:hey][:uuid] = SecureRandom.uuid if Thread.current[:hey][:uuid].nil? end |
.init_contexts! ⇒ Object
7 8 9 10 |
# File 'lib/hey/thread_cargo.rb', line 7 def self.init_contexts! init! Thread.current[:hey][:contexts] = [] if Thread.current[:hey][:contexts].nil? end |
.purge! ⇒ Object
Removes all namespaced values from the current thread.
30 31 32 |
# File 'lib/hey/thread_cargo.rb', line 30 def self.purge! Thread.current[:hey] = nil end |
.remove_context(context) ⇒ Object
Returns a context from the current thread
24 25 26 27 |
# File 'lib/hey/thread_cargo.rb', line 24 def self.remove_context(context) self.init_contexts! Thread.current[:hey][:contexts].delete(context) end |
.uuid ⇒ Object
12 13 14 15 |
# File 'lib/hey/thread_cargo.rb', line 12 def self.uuid init! Thread.current[:hey][:uuid] end |