collectiveidea / interactor

Interactor provides a common interface for performing complex user interactions.
MIT License
3.36k stars 212 forks source link

Adds Interactor path transition switch #111

Closed ahmad-elassuty closed 7 years ago

ahmad-elassuty commented 8 years ago

Introducing Switcher: a new type of Interactors. Switcher aims to provide a path transition switch mechanism. Each path can be an Interactor or an Organizer that defines multiple scenarios of application's business logic.

Flow

For example, consider the following diagram:

diagram 001

The S class in the previous diagram can be defined as:

class S
  include Interactor::Switcher

  # Switch
  # First path: [B, E]
  # Second path: C

  switch [B, E], C
end

Switcher's behaviour is controlled by switcher_condition attribute that can be provided through the library's regular context object. Hence, if context.switcher_condition equals 1, then the second path, that includes C, will be executed.

.switch class Method

The switch class method accepts arguments in one of the following flavours:

laserlemon commented 7 years ago

Closing because:

  1. The API isn't very clear or obvious.
  2. I'd like to avoid any reserved words in the context.