Sha256: f1c9f67dcbae7ae4d46e7fd60cb18ee1b0974aecba6a26edce06d1be132efd8d

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

# ActionPolicy is an authorization framework for Ruby/Rails applications.
#
# It provides a way to write access policies and helpers to check these policies
# in your application.
module ActionPolicy
  class Error < StandardError; end

  # Raised when Action Policy fails to find a policy class for a record.
  class NotFound < Error
    attr_reader :target, :message

    def initialize(target, message = nil)
      @target = target
      @message =
        message ||
        "Couldn't find policy class for #{target.inspect}" \
        "#{target.is_a?(Module) ? "" : " (#{target.class})"}"
    end
  end

  require "action_policy/version"
  require "action_policy/base"
  require "action_policy/lookup_chain"
  require "action_policy/behaviour"
  require "action_policy/i18n" if defined?(::I18n)

  class << self
    attr_accessor :cache_store

    # Find a policy class for a target
    def lookup(target, allow_nil: false, **options)
      LookupChain.call(target, **options) ||
        (allow_nil ? nil : raise(NotFound, target))
    end
  end

  require "action_policy/railtie" if defined?(::Rails)
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
action_policy-0.4.4 lib/action_policy.rb
action_policy-0.4.3 lib/action_policy.rb
action_policy-0.4.2 lib/action_policy.rb
action_policy-0.4.1 lib/action_policy.rb
action_policy-0.4.0 lib/action_policy.rb