Class: ActiveInteractor::Organizer::InteractorInterfaceCollection Private

Inherits:
Object
  • Object
show all
Defined in:
lib/active_interactor/organizer/interactor_interface_collection.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A collection of InteractorInterface

Author:

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInteractorInterfaceCollection

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.

Initialize a new instance of ActiveInteractor::Organizer::InteractorInterfaceCollection

Since:

  • 1.0.0



25
26
27
# File 'lib/active_interactor/organizer/interactor_interface_collection.rb', line 25

def initialize
  @collection = []
end

Instance Attribute Details

#collectionArray<InteractorInterface> (readonly)

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.

An array of ActiveInteractor::Organizer::InteractorInterface

Returns:

Since:

  • 1.0.0



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/active_interactor/organizer/interactor_interface_collection.rb', line 15

class InteractorInterfaceCollection
  attr_reader :collection

  # @!method map(&block)
  #  Invokes the given block once for each element of {#collection}.
  #  @return [Array] a new array containing the values returned by the block.
  delegate :map, to: :collection

  # Initialize a new instance of {InteractorInterfaceCollection}
  # @return [InteractorInterfaceCollection] a new instance of {InteractorInterfaceCollection}
  def initialize
    @collection = []
  end

  # Add an {InteractorInterface} to the {#collection}
  #
  # @param interactor_class [Const, Symbol, String] an {ActiveInteractor::Base interactor} class
  # @param filters [Hash{Symbol=> Proc, Symbol}] conditional options for the {ActiveInteractor::Base interactor}
  #  class
  # @option filters [Proc, Symbol] :if only call the {ActiveInteractor::Base interactor}
  #  {Interactor::Perform::ClassMethods#perform .perform} if `Proc` or `method` returns `true`
  # @option filters [Proc, Symbol] :unless only call the {ActiveInteractor::Base interactor}
  #  {Interactor::Perform::ClassMethods#perform .perform} if `Proc` or `method` returns `false` or `nil`
  # @return [self] the {InteractorInterfaceCollection} instance
  def add(interactor_class, filters = {})
    interface = ActiveInteractor::Organizer::InteractorInterface.new(interactor_class, filters)
    collection << interface if interface.interactor_class
    self
  end

  # Add multiple {InteractorInterface} to the {#collection}
  #
  # @param interactor_classes [Array<Const, Symbol, String>] the {ActiveInteractor::Base interactor} classes
  # @return [self] the {InteractorInterfaceCollection} instance
  def concat(interactor_classes)
    interactor_classes.flatten.each { |interactor_class| add(interactor_class) }
    self
  end

  # Calls the given block once for each element in {#collection}, passing that element as a parameter.
  # @return [self] the {InteractorInterfaceCollection} instance
  def each(&block)
    collection.each(&block) if block
    self
  end
end

Instance Method Details

#add(interactor_class, filters = {}) ⇒ 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.

Add an ActiveInteractor::Organizer::InteractorInterface to the #collection

Parameters:

  • interactor_class (Const, Symbol, String)

    an interactor class

  • filters (Hash{Symbol=> Proc, Symbol}) (defaults to: {})

    conditional options for the interactor class

Options Hash (filters):

  • :if (Proc, Symbol)

    only call the interactor .perform if Proc or method returns true

  • :unless (Proc, Symbol)

    only call the interactor .perform if Proc or method returns false or nil

Returns:

Since:

  • 1.0.0



39
40
41
42
43
# File 'lib/active_interactor/organizer/interactor_interface_collection.rb', line 39

def add(interactor_class, filters = {})
  interface = ActiveInteractor::Organizer::InteractorInterface.new(interactor_class, filters)
  collection << interface if interface.interactor_class
  self
end

#concat(interactor_classes) ⇒ 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.

Add multiple ActiveInteractor::Organizer::InteractorInterface to the #collection

Parameters:

  • interactor_classes (Array<Const, Symbol, String>)

    the interactor classes

Returns:

Since:

  • 1.0.0



49
50
51
52
# File 'lib/active_interactor/organizer/interactor_interface_collection.rb', line 49

def concat(interactor_classes)
  interactor_classes.flatten.each { |interactor_class| add(interactor_class) }
  self
end

#each(&block) ⇒ 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.

Calls the given block once for each element in #collection, passing that element as a parameter.

Returns:

Since:

  • 1.0.0



56
57
58
59
# File 'lib/active_interactor/organizer/interactor_interface_collection.rb', line 56

def each(&block)
  collection.each(&block) if block
  self
end

#map(&block) ⇒ Array

Invokes the given block once for each element of #collection.

Returns:

  • (Array)

    a new array containing the values returned by the block.



21
# File 'lib/active_interactor/organizer/interactor_interface_collection.rb', line 21

delegate :map, to: :collection