Class: Wines::UpdateWine

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

Instance Method Summary collapse

Constructor Details

#initialize(current_user) ⇒ UpdateWine

Returns a new instance of UpdateWine.



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

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

Instance Method Details

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

Yields:



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

def call(wine_id, wine_params)
  wine = self.repo.get(wine_id)
  return unless authorize_wine_update(wine, &Proc.new)

  wine = self.repo.update(self.current_caller, wine_id, wine_params)

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