Class: WinewooUser::Cellar::CreateCellarEntry

Inherits:
BaseUseCase
  • Object
show all
Defined in:
lib/winewoo_core/use_cases/winewoo_user/cellar/create_cellar_entry.rb

Instance Method Summary collapse

Constructor Details

#initialize(log_params = nil) ⇒ CreateCellarEntry

Returns a new instance of CreateCellarEntry.



4
5
6
# File 'lib/winewoo_core/use_cases/winewoo_user/cellar/create_cellar_entry.rb', line 4

def initialize(log_params=nil)
  super(WinewooCore.cellar_repo.new, log_params)
end

Instance Method Details

#call(winewoo_user, entry_params) {|entry.persisted? ? UseCaseResults.success(entry) : UseCaseResults.failure(entry.errors)| ... } ⇒ Object

Yields:



9
10
11
12
13
14
15
16
# File 'lib/winewoo_core/use_cases/winewoo_user/cellar/create_cellar_entry.rb', line 9

def call(winewoo_user, entry_params)
  entry = self.repo.create(winewoo_user, entry_params)
  self.log_repo.create(complete_log_params(entry)) if entry.persisted?

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