Class: UseCases::UseCase

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#dispatcherObject (readonly)

Returns the value of attribute dispatcher.



9
10
11
# File 'lib/bas/use_cases/use_case.rb', line 9

def dispatcher
  @dispatcher
end

#fetcherObject (readonly)

Returns the value of attribute fetcher.



9
10
11
# File 'lib/bas/use_cases/use_case.rb', line 9

def fetcher
  @fetcher
end

#formatterObject (readonly)

Returns the value of attribute formatter.



9
10
11
# File 'lib/bas/use_cases/use_case.rb', line 9

def formatter
  @formatter
end

#mapperObject (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

#performObject

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