Class: Rack::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/store.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Store

Returns a new instance of Store.



3
4
5
# File 'lib/rack/store.rb', line 3

def initialize(app)
  @app = app
end

Class Method Details

.cleanup_garbage_keysObject



28
29
30
31
32
33
# File 'lib/rack/store.rb', line 28

def cleanup_garbage_keys
  living_thread_ids = Thread.list.map(&:object_id)
  @env.delete_if do |thread_id, value|
    !living_thread_ids.include?(thread_id)
  end
end

.envObject



13
14
15
16
# File 'lib/rack/store.rb', line 13

def env
  @env ||= {}
  @env[Thread.current.object_id] ||= {}
end

.env=(env) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/rack/store.rb', line 18

def env=(env)
  @env ||= {}
  if !@env.has_key?(Thread.current.object_id) && Thread.current != Thread.main
    ObjectSpace.define_finalizer(Thread.current) do
      @env.delete thread_id
    end
  end
  @env[Thread.current.object_id] = env
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
# File 'lib/rack/store.rb', line 7

def call(env)
  self.class.env = env
  @app.call(env)
end