Class: ActiveInteractor::Organizer::Base

Inherits:
Base
  • Object
show all
Extended by:
Callbacks::ClassMethods, Organize::ClassMethods, Perform::ClassMethods
Includes:
Callbacks, Perform
Defined in:
lib/active_interactor/organizer/base.rb

Overview

The base organizer class all organizers should inherit from.

Author:

Since:

  • 1.0.0

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.parallelBoolean (readonly) Originally defined in module Perform::ClassMethods

If true the organizer will call #perform on its .organized interactors in parallel. An organizer will have parallel false by default.

Returns:

Since:

  • 1.0.0

Class Method Details

.after_all_perform(*filters, &block) ⇒ Object Originally defined in module Callbacks::ClassMethods

Define a callback to call after all organized interactors' #perform methods have been called.

Examples:

class MyInteractor1 < ActiveInteractor::Base
  def perform
    puts 'MyInteractor1'
  end
end

class MyInteractor2 < ActiveInteractor::Base
  def perform
    puts 'MyInteractor2'
  end
end

class MyOrganizer < ActiveInteractor::Organizer
  after_all_perform :print_done

  organized MyInteractor1, MyInteractor2

  private

  def print_done
    puts 'Done'
  end
end

MyOrganizer.perform
"MyInteractor1"
"MyInteractor2"
"Done"
#=> <MyOrganizer::Context>

Since:

  • v1.2.0

.after_each_perform(*filters, &block) ⇒ Object Originally defined in module Callbacks::ClassMethods

Define a callback to call after each organized interactor's #perform method has been called.

Examples:

class MyInteractor1 < ActiveInteractor::Base
  def perform
    puts 'MyInteractor1'
  end
end

class MyInteractor2 < ActiveInteractor::Base
  def perform
    puts 'MyInteractor2'
  end
end

class MyOrganizer < ActiveInteractor::Organizer
  after_each_perform :print_done

  organized MyInteractor1, MyInteractor2

  private

  def print_done
    puts 'Done'
  end
end

MyOrganizer.perform
"MyInteractor1"
"Done"
"MyInteractor2"
"Done"
#=> <MyOrganizer::Context>

Since:

  • 0.1.3

.around_all_perform(*filters, &block) ⇒ Object Originally defined in module Callbacks::ClassMethods

Define a callback to call around all organized interactors' #perform method calls.

Examples:

class MyInteractor1 < ActiveInteractor::Base
  def perform
    puts 'MyInteractor1'
    sleep(1)
  end
end

class MyInteractor2 < ActiveInteractor::Base
  def perform
    puts 'MyInteractor2'
    sleep(1)
  end
end

class MyOrganizer < ActiveInteractor::Organizer
  around_all_perform :print_time

  organized MyInteractor1, MyInteractor2

  private

  def print_time
    puts Time.now.utc
    yield
    puts Time.now.utc
  end
end

MyOrganizer.perform
"2019-04-01 00:00:00 UTC"
"MyInteractor1"
"MyInteractor2"
"2019-04-01 00:00:02 UTC"
#=> <MyOrganizer::Context>

Since:

  • v1.2.0

.around_each_perform(*filters, &block) ⇒ Object Originally defined in module Callbacks::ClassMethods

Define a callback to call around each organized interactor's #perform method call.

Examples:

class MyInteractor1 < ActiveInteractor::Base
  def perform
    puts 'MyInteractor1'
    sleep(1)
  end
end

class MyInteractor2 < ActiveInteractor::Base
  def perform
    puts 'MyInteractor2'
    sleep(1)
  end
end

class MyOrganizer < ActiveInteractor::Organizer
  around_each_perform :print_time

  organized MyInteractor1, MyInteractor2

  private

  def print_time
    puts Time.now.utc
    yield
    puts Time.now.utc
  end
end

MyOrganizer.perform
"2019-04-01 00:00:00 UTC"
"MyInteractor1"
"2019-04-01 00:00:01 UTC"
"2019-04-01 00:00:01 UTC"
"MyInteractor2"
"2019-04-01 00:00:02 UTC"
#=> <MyOrganizer::Context>

Since:

  • 0.1.3

.before_all_perform(*filters, &block) ⇒ Object Originally defined in module Callbacks::ClassMethods

Define a callback to call before all organized interactors' #perform methods have been called.

Examples:

class MyInteractor1 < ActiveInteractor::Base
  def perform
    puts 'MyInteractor1'
  end
end

class MyInteractor2 < ActiveInteractor::Base
  def perform
    puts 'MyInteractor2'
  end
end

class MyOrganizer < ActiveInteractor::Organizer
  before_all_perform :print_starting

  organized MyInteractor1, MyInteractor2

  private

  def print_starting
    puts 'Starting'
  end
end

MyOrganizer.perform
"Starting"
"MyInteractor1"
"MyInteractor2"
#=> <MyOrganizer::Context>

Since:

  • v1.2.0

.before_each_perform(*filters, &block) ⇒ Object Originally defined in module Callbacks::ClassMethods

Define a callback to call before each organized interactor's #perform method has been called.

Examples:

class MyInteractor1 < ActiveInteractor::Base
  def perform
    puts 'MyInteractor1'
  end
end

class MyInteractor2 < ActiveInteractor::Base
  def perform
    puts 'MyInteractor2'
  end
end

class MyOrganizer < ActiveInteractor::Organizer
  before_each_perform :print_starting

  organized MyInteractor1, MyInteractor2

  private

  def print_starting
    puts 'Starting'
  end
end

MyOrganizer.perform
"Starting"
"MyInteractor1"
"Starting"
"MyInteractor2"
#=> <MyOrganizer::Context>

Since:

  • 0.1.3

.organize(*interactors, &block) ⇒ InteractorInterfaceCollection Originally defined in module Organize::ClassMethods

Organize interactors to be called by the organizer. A block will be evaluated on the InteractorInterfaceCollection if a block is given.

Examples:

Basic organization of interactors

class MyInteractor1 < ActiveInteractor::Base; end
class MyInteractor2 < ActiveInteractor::Base; end
class MyOrganizer < ActiveInteractor::Organizer::Base
  organize :my_interactor_1, :my_interactor_2
end

Conditional organization of interactors

class MyInteractor1 < ActiveInteractor::Base; end
class MyInteractor2 < ActiveInteractor::Base; end
class MyOrganizer < ActiveInteractor::Organizer::Base
  organize do
    add :my_interactor_1
    add :my_interactor_2, if: -> { context.valid? }
  end
end

organization of interactors with options

class MyInteractor1 < ActiveInteractor::Base; end
class MyInteractor2 < ActiveInteractor::Base; end
class MyOrganizer < ActiveInteractor::Organizer::Base
  organize do
    add :my_interactor_1, validate: false
    add :my_interactor_2, skip_perform_callbacks: true
  end
end

Parameters:

  • interactors (Array<Const, Symbol, String>, nil)

    the Base interactor classes to be organized

Returns:

Since:

  • 0.1.0

.organizedInteractorInterfaceCollection Originally defined in module Organize::ClassMethods

An organized collection of interactors

Returns:

Since:

  • 1.0.0

.perform_in_parallelObject Originally defined in module Perform::ClassMethods

Set parallel to true

Examples:

a basic organizer set to perform in parallel

class MyOrganizer < ActiveInteractor::Organizer::Base
  perform_in_parallel
end

Since:

  • 1.0.0

Instance Method Details

#performObject Originally defined in module Perform

Call the .organized interactors #perform. An organizer is expected not to define its own #perform method in favor of this default implementation.

Since:

  • 1.0.0

#run_deferred_after_perform_callbacks_on_childrenObject Originally defined in module Perform

Since:

  • 1.0.0