module ActiveInteractor::Interactor::Perform::ClassMethods

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

@author Aaron Allen <hello@aaronmallen.me> @since 1.0.0

Public Instance Methods

perform(context = {}, options = {}) click to toggle source

Initialize a new {Base interactor} instance and call its {Interactor::Perform#perform perform} method. This is the default api to interact with all {Base interactors}.

@since 0.1.0

@example

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

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

@param context [Hash, Class] attributes to assign to the {Base interactor} instance's

{ActiveInteractor::Context::Base context} instance

@param options [Hash, Perform::Options] options to use for the {.perform}. See {Perform::Options} @return [Class] an instance of the {Base interactor} class' {ActiveInteractor::Context::Base context}

instance
# File lib/active_interactor/interactor/perform.rb, line 38
def perform(context = {}, options = {})
  new(context).with_options(options).execute_perform
end
perform!(context = {}, options = {}) click to toggle source

Initialize a new {Base interactor} instance and call its {Interactor::Perform#perform perform} method without rescuing {ActiveInteractor::Error::ContextFailure}.

@since 0.1.0

@example Calling {Perform::ClassMethods#perform! .perform!} without failure

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

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

@example Calling {Perform::ClassMethods#perform! .perform!} with failure

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

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

@param context [Hash, Class] attributes to assign to the {Base interactor} instance's

{ActiveInteractor::Context::Base context} instance

@param options [Hash, Perform::Options] options to use for the {.perform}. See {Perform::Options} @raise [Error::ContextFailure] if the {ActiveInteractor::Context::Base context} instance

fails.

@return [Class] an instance of the {Base interactor} class' {ActiveInteractor::Context::Base context}

instance
# File lib/active_interactor/interactor/perform.rb, line 75
def perform!(context = {}, options = {})
  new(context).with_options(options).execute_perform!
end