Module: RequestStore

Defined in:
lib/request_store/middleware.rb,
lib/request_store.rb,
lib/request_store/railtie.rb,
lib/request_store/version.rb

Overview

A middleware that ensures the RequestStore stays around until the last part of the body is rendered. This is useful when using streaming.

Uses Rack::BodyProxy, adapted from Rack::Lock’s usage of the same pattern.

Defined Under Namespace

Classes: Middleware, Railtie

Constant Summary collapse

VERSION =
"1.7.0"

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



34
35
36
# File 'lib/request_store.rb', line 34

def self.[](key)
  store[key]
end

.[]=(key, value) ⇒ Object



42
43
44
# File 'lib/request_store.rb', line 42

def self.[]=(key, value)
  store[key] = value
end

.active?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/request_store.rb', line 26

def self.active?
  Thread.current[:request_store_active] || false
end

.begin!Object



18
19
20
# File 'lib/request_store.rb', line 18

def self.begin!
  Thread.current[:request_store_active] = true
end

.clear!Object



14
15
16
# File 'lib/request_store.rb', line 14

def self.clear!
  Thread.current[:request_store] = {}
end

.delete(key, &block) ⇒ Object



55
56
57
# File 'lib/request_store.rb', line 55

def self.delete(key, &block)
  store.delete(key, &block)
end

.end!Object



22
23
24
# File 'lib/request_store.rb', line 22

def self.end!
  Thread.current[:request_store_active] = false
end

.exist?(key) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/request_store.rb', line 46

def self.exist?(key)
  store.key?(key)
end

.fetch(key) ⇒ Object



50
51
52
53
# File 'lib/request_store.rb', line 50

def self.fetch(key)
  store[key] = yield unless exist?(key)
  store[key]
end

.read(key) ⇒ Object



30
31
32
# File 'lib/request_store.rb', line 30

def self.read(key)
  store[key]
end

.storeObject



6
7
8
# File 'lib/request_store.rb', line 6

def self.store
  Thread.current[:request_store] ||= {}
end

.store=(store) ⇒ Object



10
11
12
# File 'lib/request_store.rb', line 10

def self.store=(store)
  Thread.current[:request_store] = store
end

.write(key, value) ⇒ Object



38
39
40
# File 'lib/request_store.rb', line 38

def self.write(key, value)
  store[key] = value
end