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:
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:
List of Interactor class arguments:
#1st path: A
#2nd path: B
#3rd path: C
switch A, B, C
Where each argument is considered as a separate path.
A path can be selected by its index.
An array of arguments:
#path: A, B, C
switch [A, B, C]
Defines a single path.
A path can be selected by its index.
A hash of arguments:
#1st path: A, B
#2nd path: C
switch key_1: [A, B], key_2: C
Where each key refers to a separate path.
A path can be selected by its key.
General Note:
A path is an Array input.
If switcher_condition is not available, the switcher executes the first path by default.
TODO
Fix comments and tests' description typos.
Add the ability to change the control argument name per switcher. switcher_condition
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:
The S class in the previous diagram can be defined as:
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:
List of Interactor class arguments:
An array of arguments:
A hash of arguments:
General Note:
TODO