module RequestStore
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.
Constants
- VERSION
Public Class Methods
[](key)
click to toggle source
# File lib/request_store.rb, line 34 def self.[](key) store[key] end
[]=(key, value)
click to toggle source
# File lib/request_store.rb, line 42 def self.[]=(key, value) store[key] = value end
active?()
click to toggle source
# File lib/request_store.rb, line 26 def self.active? Thread.current[:request_store_active] || false end
begin!()
click to toggle source
# File lib/request_store.rb, line 18 def self.begin! Thread.current[:request_store_active] = true end
clear!()
click to toggle source
# File lib/request_store.rb, line 14 def self.clear! Thread.current[:request_store] = {} end
delete(key, &block)
click to toggle source
# File lib/request_store.rb, line 55 def self.delete(key, &block) store.delete(key, &block) end
end!()
click to toggle source
# File lib/request_store.rb, line 22 def self.end! Thread.current[:request_store_active] = false end
exist?(key)
click to toggle source
# File lib/request_store.rb, line 46 def self.exist?(key) store.key?(key) end
fetch(key) { || ... }
click to toggle source
# File lib/request_store.rb, line 50 def self.fetch(key) store[key] = yield unless exist?(key) store[key] end
read(key)
click to toggle source
# File lib/request_store.rb, line 30 def self.read(key) store[key] end
store()
click to toggle source
# File lib/request_store.rb, line 6 def self.store Thread.current[:request_store] ||= {} end
store=(store)
click to toggle source
# File lib/request_store.rb, line 10 def self.store=(store) Thread.current[:request_store] = store end
write(key, value)
click to toggle source
# File lib/request_store.rb, line 38 def self.write(key, value) store[key] = value end