class WinewooCore::UseCases::Wines::ShowVintage

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/show_vintage.rb, line 4
def initialize(current_user, log_params=nil)
  super(WinewooCore.vintages_repo.new, log_params)
  self.current_caller = current_user
end

Public Instance Methods

call(wine_id, vintage_id, options={}) { |vintage ? found: not_found| ... } click to toggle source
# File lib/winewoo_core/use_cases/wines/show_vintage.rb, line 10
def call(wine_id, vintage_id, options={})
  wine = WinewooCore.wines_repo.new.get(wine_id)
  return unless authorize_vintage_show(wine, &Proc.new)

  vintage = self.repo.get(wine_id, vintage_id)
  vintage = nil if wine && wine.draft? && options[:only_published]
  # TODO UNOFFICIALS
  # vintage = nil if wine && wine.unofficial? && options[:only_published]

  yield vintage ?
    UseCaseResults.found(vintage) :
    UseCaseResults.not_found
end

Private Instance Methods

authorize_vintage_show(wine) { |unauthorized| ... } click to toggle source
# File lib/winewoo_core/use_cases/wines/show_vintage.rb, line 27
def authorize_vintage_show(wine)
  auth_params = authorization_params_for(:wine, :show?, wine)
  res = self.authorizer.authorize_action(auth_params)
  yield UseCaseResults.unauthorized unless res
  return res
end