Method: ActiveSupport::ExecutionContext.set
- Defined in:
- lib/active_support/execution_context.rb
.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.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/active_support/execution_context.rb', line 46 def set(**) .symbolize_keys! keys = .keys store = record.store previous_context = if block_given? keys.zip(store.values_at(*keys)).to_h end 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 |