module ActiveInteractor::Interactor::Perform
Interactor
perform methods. Because {Perform} is a module classes should include {Perform} rather than inherit from it.
@author Aaron Allen <hello@aaronmallen.me> @since 1.0.0
Public Instance Methods
Duplicate an {Base interactor} instance as well as it's {#options} and {ActiveInteractor::Context::Base context} instances.
@return [Base] a duplicated {Base interactor} instance
# File lib/active_interactor/interactor/perform.rb, line 177 def deep_dup dupped = dup %w[@context @options].each do |variable| dupped.instance_variable_set(variable, instance_variable_get(variable)&.dup) end dupped end
Options
for the {Base interactor} {#perform}
@return [Options] an instance of {Options}
# File lib/active_interactor/interactor/perform.rb, line 188 def options @options ||= ActiveInteractor::Interactor::Perform::Options.new end
The steps to run when an {Base interactor} is called. An {Base interactor's} {#perform} method should never be called directly on an {Base interactor} instance and should instead be invoked by the {Base interactor's} class method {Perform::ClassMethods#perform .perform}.
@since 0.1.0
@abstract {Base interactors} should override {#perform} with the appropriate steps and
{ActiveInteractor::Context::Base context} mutations required for the {Base interactor} to do its work.
@example
class MyInteractor < ActiveInteractor::Base def perform context.first_name = 'Aaron' end end MyInteractor.perform #=> <#MyInteractor::Context first_name='Aaron'>
# File lib/active_interactor/interactor/perform.rb, line 210 def perform; end
The steps to run when an {Base interactor} {ActiveInteractor::Context::Status#fail! fails}. An {Base interactor's} {#rollback} method should never be called directly and is instead called by the {Base interactor's} {ActiveInteractor::Context::Base context} when {ActiveInteractor::Context::Status#fail! fail} is called.
@since 0.1.0
@abstract {Base interactors} should override {#rollback} with the appropriate steps and
{ActiveInteractor::Context::Base context} mutations required for the {Base interactor} to roll back its work.
@example
class MyInteractor < ActiveInteractor::Base def perform context.first_name = 'Aaron' context.fail! end def rollback context.first_name = 'Bob' end end MyInteractor.perform #=> <#MyInteractor::Context first_name='Bob'>
# File lib/active_interactor/interactor/perform.rb, line 236 def rollback; end
Set {Options options} for an {Base interactor's} {#perform}
@api private
@param options [Hash, Perform::Options] options to use for the perform call. See {Perform::Options} @return [self] the {Base interactor} instance
# File lib/active_interactor/interactor/perform.rb, line 244 def with_options(options) @options = if options.is_a?(ActiveInteractor::Interactor::Perform::Options) options else ActiveInteractor::Interactor::Perform::Options.new(options) end self end
Private Instance Methods
# File lib/active_interactor/interactor/perform.rb, line 255 def worker ActiveInteractor::Interactor::Worker.new(self) end