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
# File 'lib/active_interactor/interactor/perform.rb', line 177

def deep_dup
  self.class.new(context.dup).with_options(options.dup)
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

API:

  • private



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

API:

  • private



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



184
185
186
# File 'lib/active_interactor/interactor/perform.rb', line 184

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



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

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



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

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:

  • options to use for the perform call. See Options

Returns:

Since:

  • 1.0.0

API:

  • private



240
241
242
243
244
245
246
247
# File 'lib/active_interactor/interactor/perform.rb', line 240

def with_options(options)
  @options = if options.is_a?(ActiveInteractor::Interactor::Perform::Options)
               options
             else
               ActiveInteractor::Interactor::Perform::Options.new(options)
             end
  self
end