2021-08-19 17:50:24 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-23 10:02:06 +02:00
|
|
|
require "dry-initializer"
|
2021-08-19 17:50:24 +02:00
|
|
|
|
|
|
|
module UseCase
|
|
|
|
class Base
|
|
|
|
extend Dry::Initializer
|
|
|
|
|
2022-07-23 11:59:01 +02:00
|
|
|
def self.call(...) = new(...).call
|
2021-08-19 17:50:24 +02:00
|
|
|
|
2022-07-23 11:59:01 +02:00
|
|
|
def call = raise NotImplementedError
|
2023-02-10 11:34:55 +01: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 17:50:24 +02:00
|
|
|
end
|
2022-07-23 10:02:06 +02:00
|
|
|
end
|