2021-08-19 08:50:24 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-23 01:02:06 -07:00
|
|
|
require "dry-initializer"
|
2021-08-19 08:50:24 -07:00
|
|
|
|
|
|
|
module UseCase
|
|
|
|
class Base
|
|
|
|
extend Dry::Initializer
|
|
|
|
|
2022-07-23 02:59:01 -07:00
|
|
|
def self.call(...) = new(...).call
|
2021-08-19 08:50:24 -07:00
|
|
|
|
2022-07-23 02:59:01 -07:00
|
|
|
def call = raise NotImplementedError
|
2023-02-10 02:34:55 -08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def authorize!(verb, user, record, error_class: Errors::NotAuthorized)
|
|
|
|
raise error_class unless Pundit.policy!(user, record).public_send("#{verb}?")
|
|
|
|
end
|
2021-08-19 08:50:24 -07:00
|
|
|
end
|
2022-07-23 01:02:06 -07:00
|
|
|
end
|