Module: ActiveSupport::ExecutionContext
- Defined in:
- lib/active_support/execution_context.rb
Overview
:nodoc:
Defined Under Namespace
Modules: TestHelper
Class Method Summary collapse
- .[]=(key, value) ⇒ Object
- .after_change(&block) ⇒ Object
- .clear ⇒ Object
-
.set(**options) ⇒ Object
Updates the execution context.
- .to_h ⇒ Object
Class Method Details
.[]=(key, value) ⇒ Object
34 35 36 37 |
# File 'lib/active_support/execution_context.rb', line 34 def []=(key, value) store[key.to_sym] = value @after_change_callbacks.each(&:call) end |
.after_change(&block) ⇒ Object
7 8 9 |
# File 'lib/active_support/execution_context.rb', line 7 def after_change(&block) @after_change_callbacks << block end |
.clear ⇒ Object
43 44 45 |
# File 'lib/active_support/execution_context.rb', line 43 def clear store.clear end |
.set(**options) ⇒ Object
Updates the execution context. If a block is given, it resets the provided keys to their previous value once the block exits.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_support/execution_context.rb', line 13 def set(**) .symbolize_keys! keys = .keys store = self.store previous_context = keys.zip(store.values_at(*keys)).to_h store.merge!() @after_change_callbacks.each(&:call) if block_given? begin yield ensure store.merge!(previous_context) @after_change_callbacks.each(&:call) end end end |
.to_h ⇒ Object
39 40 41 |
# File 'lib/active_support/execution_context.rb', line 39 def to_h store.dup end |