Module: ActiveInteractor::Interactor::Perform

Included in:
Base
Defined in:
lib/active_interactor/interactor/perform.rb

Overview

Interactor perform methods. Because Perform is a module classes should include Perform rather than inherit from it.

Author:

Since:

  • 1.0.0

Defined Under Namespace

Modules: ClassMethods Classes: Options

Instance Method Summary collapse

Instance Method Details

#deep_dupBase

Duplicate an interactor instance as well as it's #options and context instances.

Returns:

Since:

  • 1.0.0



177
178
179
180
181
182
183
# 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

#execute_performObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run the interactor instance's #perform with callbacks and validation.

Since:

  • 0.1.0



171
# File 'lib/active_interactor/interactor/perform.rb', line 171

delegate :execute_perform, :execute_perform!, to: :worker

#execute_perform!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run the interactor instance's #perform with callbacks and validation without rescuing Error::ContextFailure.

Since:

  • 0.1.0



171
# File 'lib/active_interactor/interactor/perform.rb', line 171

delegate :execute_perform, :execute_perform!, to: :worker

#optionsOptions

Options for the interactor #perform

Returns:

Since:

  • 1.0.0



188
189
190
# File 'lib/active_interactor/interactor/perform.rb', line 188

def options
  @options ||= ActiveInteractor::Interactor::Perform::Options.new
end

#performObject

This method is abstract.

interactors should override #perform with the appropriate steps and context mutations required for the interactor to do its work.

The steps to run when an interactor is called. An interactor's #perform method should never be called directly on an interactor instance and should instead be invoked by the interactor's class method .perform.

Examples:

class MyInteractor < ActiveInteractor::Base
  def perform
    context.first_name = 'Aaron'
  end
end

MyInteractor.perform
#=> <#MyInteractor::Context first_name='Aaron'>

Since:

  • 0.1.0



210
# File 'lib/active_interactor/interactor/perform.rb', line 210

def perform; end

#rollbackObject

This method is abstract.

interactors should override #rollback with the appropriate steps and context mutations required for the interactor to roll back its work.

The steps to run when an interactor fails. An interactor's #rollback method should never be called directly and is instead called by the interactor's context when #fail is called.

Examples:

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'>

Since:

  • 0.1.0



236
# File 'lib/active_interactor/interactor/perform.rb', line 236

def rollback; end

#with_options(options) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set options for an interactor's #perform

Parameters:

Returns:

Since:

  • 1.0.0



244
245
246
247
248
249
250
251
# 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