Sha256: d979f04a3ff8b1464228ec7a91418bd9c9184e656cb7b8393068095076b33919
Contents?: true
Size: 747 Bytes
Versions: 5
Compression:
Stored size: 747 Bytes
Contents
# frozen_string_literal: true module ActionPolicy # Raised when `authorize!` check fails class Unauthorized < Error attr_reader :policy, :rule, :reasons def initialize(policy, rule) @policy = policy.class @rule = rule # Reasons module could be not included @reasons = policy.reasons if policy.respond_to?(:reasons) end end # Performs authorization, raises an exception when check failed. # # The main purpose of this module is to extact authorize action # from everything else to make it easily testable. module Authorizer class << self def call(policy, rule) policy.apply(rule) || raise(::ActionPolicy::Unauthorized.new(policy, rule)) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems