Module: ActiveSupport::ExecutionContext
- Defined in:
- lib/active_support/execution_context.rb
Overview
Defined Under Namespace
Modules: TestHelper
Classes: Record
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
Returns the value of attribute nestable.
38
39
40
|
# File 'lib/active_support/execution_context.rb', line 38
def nestable
@nestable
end
|
Class Method Details
.[]=(key, value) ⇒ Object
69
70
71
72
|
# File '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) ⇒ Object
40
41
42
|
# File 'lib/active_support/execution_context.rb', line 40
def after_change(&block)
@after_change_callbacks << block
end
|
96
97
98
|
# File 'lib/active_support/execution_context.rb', line 96
def clear
IsolatedExecutionState[:active_support_execution_context] = nil
end
|
.current_attributes_instances ⇒ Object
100
101
102
|
# File 'lib/active_support/execution_context.rb', line 100
def current_attributes_instances
record.current_attributes_instances
end
|
87
88
89
90
91
92
93
94
|
# File 'lib/active_support/execution_context.rb', line 87
def pop
if @nestable
record.pop
else
clear
end
self
end
|
78
79
80
81
82
83
84
85
|
# File 'lib/active_support/execution_context.rb', line 78
def push
if @nestable
record.push
else
clear
end
self
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.
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(**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
|
74
75
76
|
# File 'lib/active_support/execution_context.rb', line 74
def to_h
record.store.dup
end
|