Module: ActiveInteractor::Organizer::Organize::ClassMethods

Included in:
Base
Defined in:
lib/active_interactor/organizer/organize.rb

Overview

Organizer organize 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

#organize(*interactors, &block) ⇒ InteractorInterfaceCollection

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



52
53
54
55
56
# File 'lib/active_interactor/organizer/organize.rb', line 52

def organize(*interactors, &block)
  organized.concat(interactors) if interactors
  organized.instance_eval(&block) if block
  organized
end

#organizedInteractorInterfaceCollection

An organized collection of interactors

Returns:

Since:

  • 1.0.0



61
62
63
# File 'lib/active_interactor/organizer/organize.rb', line 61

def organized
  @organized ||= ActiveInteractor::Organizer::InteractorInterfaceCollection.new
end