Class: ActiveSupport::ExecutionWrapper
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
|
|
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
DescendantsTracker
|
|
|
Instance Chain:
self,
Callbacks
|
|
| Inherits: | Object |
| Defined in: | activesupport/lib/active_support/execution_wrapper.rb |
Constant Summary
Callbacks - Included
Callbacks - Attributes & Methods
- .__callbacks rw
- #__callbacks readonly
- .__callbacks? ⇒ Boolean rw
- #__callbacks? ⇒ Boolean readonly
Class Attribute Summary
- .active rw
Class Method Summary
-
.register_hook(hook, outer: false)
Register an object to be invoked during both the
runandcompletesteps. -
.run!(reset: false)
Run this execution.
- .to_complete(*args, &block)
- .to_run(*args, &block)
-
.wrap
Perform the work in the supplied block as an execution.
DescendantsTracker - self
| clear, descendants, direct_descendants, | |
| store_inherited | This is the only method that is not thread safe, but is only ever called during the eager loading phase. |
| subclasses | Alias for DescendantsTracker.direct_descendants. |
Instance Method Summary
-
#complete!
Complete this in-flight execution.
Callbacks - Included
| #run_callbacks | Runs the callbacks for the given event. |
Class Attribute Details
.__callbacks (rw)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 67
class_attribute :__callbacks, instance_writer: false, default: {}
.__callbacks? ⇒ Boolean (rw)
[ GitHub ]
# File 'activesupport/lib/active_support/callbacks.rb', line 67
class_attribute :__callbacks, instance_writer: false, default: {}
.active (rw)
[ GitHub ]# File 'activesupport/lib/active_support/execution_wrapper.rb', line 98
attr_accessor :active
Class Method Details
.register_hook(hook, outer: false)
Register an object to be invoked during both the run and complete steps.
hook.complete will be passed the value returned from hook.run, and will only be invoked if run has previously been called. (Mostly, this means it won’t be invoked if an exception occurs in a preceding .to_run block; all ordinary .to_complete blocks are invoked in that situation.)
# File 'activesupport/lib/active_support/execution_wrapper.rb', line 50
def self.register_hook(hook, outer: false) if outer to_run RunHook.new(hook), prepend: true to_complete :after, CompleteHook.new(hook) else to_run RunHook.new(hook) to_complete CompleteHook.new(hook) end end
.run!(reset: false)
Run this execution.
Returns an instance, whose #complete! method must be invoked after the work has been performed.
Where possible, prefer .wrap.
# File 'activesupport/lib/active_support/execution_wrapper.rb', line 66
def self.run!(reset: false) if reset lost_instance = active.delete(Thread.current) lost_instance&.complete! else return Null if active? end new.tap do |instance| success = nil begin instance.run! success = true ensure instance.complete! unless success end end end
.to_complete(*args, &block)
[ GitHub ]# File 'activesupport/lib/active_support/execution_wrapper.rb', line 21
def self.to_complete(*args, &block) set_callback(:complete, *args, &block) end
.to_run(*args, &block)
[ GitHub ]# File 'activesupport/lib/active_support/execution_wrapper.rb', line 17
def self.to_run(*args, &block) set_callback(:run, *args, &block) end
.wrap
Perform the work in the supplied block as an execution.
Instance Attribute Details
#__callbacks (readonly)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 67
class_attribute :__callbacks, instance_writer: false, default: {}
#__callbacks? ⇒ Boolean (readonly)
[ GitHub ]
# File 'activesupport/lib/active_support/callbacks.rb', line 67
class_attribute :__callbacks, instance_writer: false, default: {}
Instance Method Details
#complete!
# File 'activesupport/lib/active_support/execution_wrapper.rb', line 121
def complete! run_callbacks(:complete) ensure self.class.active.delete Thread.current end