class Sqreen::Ecosystem::TransactionStorage
The transaction storage is a mechanism for the modules to share request-scoped data with each other or to keep request-scoped objects themselves, although, for this last use case to be effective, propagation of request start/end events to the modules will likely be needed. A more generic notification of data availability to modules also may be needed in the future.
This is not be used to share data with the Ecosystem
client
This class is not thread safe because it can call the lazy getter twice if [] is called concurrently.
Public Class Methods
create_thread_local()
click to toggle source
@return [Sqreen::Ecosystem::TransactionStorage]
# File lib/sqreen/ecosystem/transaction_storage.rb, line 26 def create_thread_local Thread.current[:tx_storage] = new end
destroy_thread_local()
click to toggle source
# File lib/sqreen/ecosystem/transaction_storage.rb, line 35 def destroy_thread_local Thread.current[:tx_storage] = nil end
fetch_thread_local()
click to toggle source
@return [Sqreen::Ecosystem::TransactionStorage]
# File lib/sqreen/ecosystem/transaction_storage.rb, line 31 def fetch_thread_local Thread.current[:tx_storage] end
new()
click to toggle source
# File lib/sqreen/ecosystem/transaction_storage.rb, line 40 def initialize @values = {} @values_lazy = {} end
Public Instance Methods
[](key)
click to toggle source
# File lib/sqreen/ecosystem/transaction_storage.rb, line 53 def [](key) v = @values[key] return v unless v.nil? v = @values_lazy[key] return nil if v.nil? begin @values[key] = v.call rescue StandardError => e logger.warn { "Error resolving key #{e} with lazy value: #{e.message}" } raise end end
[]=(key, value)
click to toggle source
# File lib/sqreen/ecosystem/transaction_storage.rb, line 45 def []=(key, value) @values[key] = value end
set_lazy(key, &block)
click to toggle source
# File lib/sqreen/ecosystem/transaction_storage.rb, line 49 def set_lazy(key, &block) @values_lazy[key] = block end