Class: UseCases::UseCase
- Inherits:
-
Object
- Object
- UseCases::UseCase
- Defined in:
- lib/bas/use_cases/use_case.rb
Overview
The UseCases::UseCase class represents a generic structure for use cases within the system. It encapsulates the logic flow by coordinating the execution of its components to fulfill a specific use case.
Instance Attribute Summary collapse
-
#dispatcher ⇒ Object
readonly
Returns the value of attribute dispatcher.
-
#fetcher ⇒ Object
readonly
Returns the value of attribute fetcher.
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#mapper ⇒ Object
readonly
Returns the value of attribute mapper.
Instance Method Summary collapse
-
#initialize(config) ⇒ UseCase
constructor
Initializes the use case with the necessary components.
-
#perform ⇒ Object
Executes the use case by orchestrating the sequential execution of the fetcher, mapper, formatter, and dispatcher.
Constructor Details
#initialize(config) ⇒ UseCase
Initializes the use case with the necessary components.
Params:
-
Usecases::Types::Config
config, The components required to instantiate a use case.
17 18 19 20 21 22 |
# File 'lib/bas/use_cases/use_case.rb', line 17 def initialize(config) @fetcher = config.fetcher @mapper = config.mapper @formatter = config.formatter @dispatcher = config.dispatcher end |
Instance Attribute Details
#dispatcher ⇒ Object (readonly)
Returns the value of attribute dispatcher.
9 10 11 |
# File 'lib/bas/use_cases/use_case.rb', line 9 def dispatcher @dispatcher end |
#fetcher ⇒ Object (readonly)
Returns the value of attribute fetcher.
9 10 11 |
# File 'lib/bas/use_cases/use_case.rb', line 9 def fetcher @fetcher end |
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
9 10 11 |
# File 'lib/bas/use_cases/use_case.rb', line 9 def formatter @formatter end |
#mapper ⇒ Object (readonly)
Returns the value of attribute mapper.
9 10 11 |
# File 'lib/bas/use_cases/use_case.rb', line 9 def mapper @mapper end |
Instance Method Details
#perform ⇒ Object
Executes the use case by orchestrating the sequential execution of the fetcher, mapper, formatter, and dispatcher.
returns Dispatcher::Discord::Types::Response
29 30 31 32 33 34 35 36 37 |
# File 'lib/bas/use_cases/use_case.rb', line 29 def perform response = fetcher.fetch mappings = mapper.map(response) formatted_payload = formatter.format(mappings) dispatcher.dispatch(formatted_payload) end |