Module: ActiveSupport::ExecutionContext

Defined in:
lib/active_support/execution_context.rb

Overview

:nodoc:

Defined Under Namespace

Modules: TestHelper Classes: Record

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.nestableObject

Returns the value of attribute nestable.



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

def nestable
  @nestable
end

Class Method Details

.[]=(key, value) ⇒ Object



76
77
78
79
# File 'lib/active_support/execution_context.rb', line 76

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

.after_change(&block) ⇒ Object



47
48
49
# File 'lib/active_support/execution_context.rb', line 47

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

.clearObject



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

def clear
  IsolatedExecutionState[:active_support_execution_context] = nil
end

.current_attributes_instancesObject



111
112
113
# File 'lib/active_support/execution_context.rb', line 111

def current_attributes_instances
  record.current_attributes_instances
end

.flushObject



107
108
109
# File 'lib/active_support/execution_context.rb', line 107

def flush
  record.flush
end

.popObject



94
95
96
97
98
99
100
101
# File 'lib/active_support/execution_context.rb', line 94

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

.pushObject



85
86
87
88
89
90
91
92
# File 'lib/active_support/execution_context.rb', line 85

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.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/active_support/execution_context.rb', line 53

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_hObject



81
82
83
# File 'lib/active_support/execution_context.rb', line 81

def to_h
  record.store.dup
end