Module: ActiveSupport::IsolatedExecutionState

Defined in:
lib/active_support/isolated_execution_state.rb

Overview

:nodoc:

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.isolation_levelObject

Returns the value of attribute isolation_level.



11
12
13
# File 'lib/active_support/isolated_execution_state.rb', line 11

def isolation_level
  @isolation_level
end

.scopeObject (readonly)

Returns the value of attribute scope.



11
12
13
# File 'lib/active_support/isolated_execution_state.rb', line 11

def scope
  @scope
end

Instance Attribute Details

#active_support_execution_stateObject

Returns the value of attribute active_support_execution_state.



7
8
9
# File 'lib/active_support/isolated_execution_state.rb', line 7

def active_support_execution_state
  @active_support_execution_state
end

Class Method Details

.[](key) ⇒ Object



31
32
33
34
35
# File 'lib/active_support/isolated_execution_state.rb', line 31

def [](key)
  if state = @scope.current.active_support_execution_state
    state[key]
  end
end

.[]=(key, value) ⇒ Object



37
38
39
40
# File 'lib/active_support/isolated_execution_state.rb', line 37

def []=(key, value)
  state = (@scope.current.active_support_execution_state ||= {})
  state[key] = value
end

.clearObject



50
51
52
# File 'lib/active_support/isolated_execution_state.rb', line 50

def clear
  @scope.current.active_support_execution_state&.clear
end

.contextObject



54
55
56
# File 'lib/active_support/isolated_execution_state.rb', line 54

def context
  scope.current
end

.delete(key) ⇒ Object



46
47
48
# File 'lib/active_support/isolated_execution_state.rb', line 46

def delete(key)
  @scope.current.active_support_execution_state&.delete(key)
end

.key?(key) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/active_support/isolated_execution_state.rb', line 42

def key?(key)
  @scope.current.active_support_execution_state&.key?(key)
end

.share_with(other, &block) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/active_support/isolated_execution_state.rb', line 58

def share_with(other, &block)
  # Action Controller streaming spawns a new thread and copy thread locals.
  # We do the same here for backward compatibility, but this is very much a hack
  # and streaming should be rethought.
  old_state, context.active_support_execution_state = context.active_support_execution_state, other.active_support_execution_state.dup
  block.call
ensure
  context.active_support_execution_state = old_state
end