123456789_123456789_123456789_123456789_123456789_

Module: ActiveSupport::ExecutionContext

Do not use. This module is for internal use only.
Relationships & Source Files
Namespace Children
Modules:
Classes:
Defined in: activesupport/lib/active_support/execution_context.rb

Class Attribute Summary

Class Method Summary

Class Attribute Details

.nestable (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/execution_context.rb', line 38

attr_accessor :nestable

Class Method Details

.[]=(key, value)

[ GitHub ]

  
# File 'activesupport/lib/active_support/execution_context.rb', line 69

def []=(key, value)
  record.store[key.to_sym] = value
  @after_change_callbacks.each(&:call)
end

.after_change(&block)

[ GitHub ]

  
# File 'activesupport/lib/active_support/execution_context.rb', line 40

def after_change(&block)
  @after_change_callbacks << block
end

.clear

[ GitHub ]

  
# File 'activesupport/lib/active_support/execution_context.rb', line 96

def clear
  IsolatedExecutionState[:active_support_execution_context] = nil
end

.current_attributes_instances

[ GitHub ]

  
# File 'activesupport/lib/active_support/execution_context.rb', line 100

def current_attributes_instances
  record.current_attributes_instances
end

.pop

[ GitHub ]

  
# File 'activesupport/lib/active_support/execution_context.rb', line 87

def pop
  if @nestable
    record.pop
  else
    clear
  end
  self
end

.push

[ GitHub ]

  
# File 'activesupport/lib/active_support/execution_context.rb', line 78

def push
  if @nestable
    record.push
  else
    clear
  end
  self
end

.record (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/execution_context.rb', line 105

def record
  IsolatedExecutionState[:active_support_execution_context] ||= Record.new
end

.set(**options)

Updates the execution context. If a block is given, it resets the provided keys to their previous value once the block exits.

[ GitHub ]

  
# File 'activesupport/lib/active_support/execution_context.rb', line 46

def set(**options)
  options.symbolize_keys!
  keys = options.keys

  store = record.store

  previous_context = if block_given?
    keys.zip(store.values_at(*keys)).to_h
  end

  store.merge!(options)
  @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

[ GitHub ]

  
# File 'activesupport/lib/active_support/execution_context.rb', line 74

def to_h
  record.store.dup
end