Module: ActiveInteractor::Interactor::Perform::ClassMethods

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

Overview

Interactor perform class methods. Because ClassMethods is a module classes should extend ClassMethods rather than inherit from it.

Author:

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#perform(context = {}, options = {}) ⇒ Class

Initialize a new interactor instance and call its #perform method. This is the default api to interact with all interactors.

Examples:

class MyInteractor < ActiveInteractor::Base
  def perform
    puts "I performed"
  end
end

MyInteractor.perform
"I performed"
#=> <#MyInteractor::Context>

Parameters:

Returns:

Since:

  • 0.1.0



38
39
40
# File 'lib/active_interactor/interactor/perform.rb', line 38

def perform(context = {}, options = {})
  new(context).with_options(options).execute_perform
end

#perform!(context = {}, options = {}) ⇒ Class

Initialize a new interactor instance and call its #perform method without rescuing Error::ContextFailure.

Examples:

Calling .perform! without failure

class MyInteractor < ActiveInteractor::Base
  def perform
    puts "I performed"
  end
end

MyInteractor.perform!
"I performed"
#=> <#MyInteractor::Context>

Calling .perform! with failure

class MyInteractor < ActiveInteractor::Base
  def perform
    context.fail!
  end
end

MyInteractor.perform!
ActiveInteractor::Error::ContextFailure "<#MyInteractor::Context>"

Parameters:

Returns:

Raises:

Since:

  • 0.1.0



75
76
77
# File 'lib/active_interactor/interactor/perform.rb', line 75

def perform!(context = {}, options = {})
  new(context).with_options(options).execute_perform!
end