Class: Wines::CreateWine

Inherits:
BaseUseCase
  • Object
show all
Defined in:
lib/winewoo_core/use_cases/wines/create_wine.rb

Instance Method Summary collapse

Constructor Details

#initialize(current_user, log_params = nil) ⇒ CreateWine

Returns a new instance of CreateWine.



4
5
6
7
# File 'lib/winewoo_core/use_cases/wines/create_wine.rb', line 4

def initialize(current_user, log_params=nil)
  super(WinewooCore.wines_repo.new, log_params)
  self.current_caller = current_user
end

Instance Method Details

#call(producer_id, wine_params, vintage_params) {|wine ? (wine.persisted? ? UseCaseResults.success(wine) : UseCaseResults.failure(wine.errors)) : UseCaseResults.not_found| ... } ⇒ Object

Yields:



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/winewoo_core/use_cases/wines/create_wine.rb', line 10

def call(producer_id, wine_params, vintage_params)
  return unless authorize_wine_creation(&Proc.new)

  wine = create_wine_and_vintage(producer_id, wine_params, vintage_params)

  yield wine ?
    (wine.persisted? ?
     UseCaseResults.success(wine) :
     UseCaseResults.failure(wine.errors)) :
    UseCaseResults.not_found
end