class WinewooCore::UseCases::Wines::CreateWine

Public Class Methods

new(current_user, log_params=nil) click to toggle source
Calls superclass method WinewooCore::UseCases::BaseUseCase::new
# 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

Public Instance Methods

call(producer_id, wine_params, vintage_params) { |wine ? (persisted? ? success: failure) : not_found| ... } click to toggle source
# 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

Private Instance Methods

authorize_wine_creation() { |unauthorized| ... } click to toggle source
# File lib/winewoo_core/use_cases/wines/create_wine.rb, line 25
def authorize_wine_creation
  auth_params = authorization_params_for(:wine, :create?)
  res = self.authorizer.authorize_action(auth_params)
  yield UseCaseResults.unauthorized unless res
  return res
end
create_wine_and_vintage(producer_id, wine_params, vintage_params) click to toggle source
# File lib/winewoo_core/use_cases/wines/create_wine.rb, line 33
def create_wine_and_vintage(producer_id, wine_params, vintage_params)
  self.repo.create(self.current_caller,
                   producer_id,
                   wine_params,
                   vintage_params)
end