retrospring/lib/use_case/base.rb
2023-02-12 20:19:50 +01:00

19 lines
387 B
Ruby

# frozen_string_literal: true
require "dry-initializer"
module UseCase
class Base
extend Dry::Initializer
def self.call(...) = new(...).call
def call = raise NotImplementedError
private
def authorize!(verb, user, record, error_class: Errors::NotAuthorized)
raise error_class unless Pundit.policy!(user, record).public_send("#{verb}?")
end
end
end