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.6.0"

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



44
45
46
# File 'lib/request_store.rb', line 44

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

.[]=(key, value) ⇒ Object



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

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

.active?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/request_store.rb', line 36

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

.begin!Object



28
29
30
# File 'lib/request_store.rb', line 28

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

.clear!Object



24
25
26
# File 'lib/request_store.rb', line 24

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

.delete(key, &block) ⇒ Object



65
66
67
# File 'lib/request_store.rb', line 65

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

.end!Object



32
33
34
# File 'lib/request_store.rb', line 32

def self.end!
  scope[:request_store_active] = false
end

.exist?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.fetch(key) ⇒ Object



60
61
62
63
# File 'lib/request_store.rb', line 60

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

.read(key) ⇒ Object



40
41
42
# File 'lib/request_store.rb', line 40

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

.scopeObject



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

def self.scope
  Fiber
end

.storeObject



16
17
18
# File 'lib/request_store.rb', line 16

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

.store=(store) ⇒ Object



20
21
22
# File 'lib/request_store.rb', line 20

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

.write(key, value) ⇒ Object



48
49
50
# File 'lib/request_store.rb', line 48

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