Module: ResetCurrentThread

Defined in:
lib/reset_current_thread.rb,
lib/reset_current_thread/version.rb,
lib/reset_current_thread/middleware.rb

Defined Under Namespace

Classes: Middleware

Constant Summary collapse

VERSION =
'0.1.0'.freeze

Class Method Summary collapse

Class Method Details

.all!Thread

Sets all items in the current thread and fiber local to nil

Returns:

  • (Thread)

    current thread object.



11
12
13
14
# File 'lib/reset_current_thread.rb', line 11

def self.all!
  fiber_locals!
  thread_locals!
end

.fiber_locals!Thread

Sets all items in the current thread fiber local to nil

Returns:

  • (Thread)

    current thread object.



19
20
21
22
23
24
# File 'lib/reset_current_thread.rb', line 19

def self.fiber_locals!
  Thread.current.keys.each do |key|
    Thread.current[key] = nil
  end
  Thread.current
end

.thread_locals!Thread

Sets all items in the current thread local to nil

Returns:

  • (Thread)

    current thread object.



29
30
31
32
33
34
# File 'lib/reset_current_thread.rb', line 29

def self.thread_locals!
  Thread.current.thread_variables.each do |key|
    Thread.current.thread_variable_set(key, nil)
  end
  Thread.current
end