Class: EnviaYa::Rates::Application::Commands::CreateRateCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/modules/rates/application/commands/create_rate_command.rb

Instance Method Summary collapse

Constructor Details

#initialize(repository:) ⇒ CreateRateCommand

Returns a new instance of CreateRateCommand.

Raises:

  • (TypeError)


9
10
11
12
13
# File 'lib/modules/rates/application/commands/create_rate_command.rb', line 9

def initialize(repository:)
  raise TypeError, "repository expected CreateRateRepository but got: #{repository.class}" unless repository.is_a?(::EnviaYa::Rates::Domain::Repositories::RatesRepository)
  
  @repository = repository
end

Instance Method Details

#execute(create_rate_dto) ⇒ Object

Raises:

  • (TypeError)


15
16
17
18
19
# File 'lib/modules/rates/application/commands/create_rate_command.rb', line 15

def execute(create_rate_dto)
  raise TypeError, "expected CreateRateDto but got: #{create_rate_dto.class}" unless create_rate_dto.is_a?(::EnviaYa::Rates::Domain::Dtos::CreateRateDto)
  
  @repository.create(create_rate_dto)
end