Sha256: 3bb0d4e2a6dd9655581853e168612361f53eddef5770717eba355237ba23d0f6

Contents?: true

Size: 942 Bytes

Versions: 9

Compression:

Stored size: 942 Bytes

Contents

require 'effective_resources/engine'
require 'effective_resources/version'

module EffectiveResources

  # The following are all valid config keys
  mattr_accessor :authorization_method

  def self.setup
    yield self
  end

  def self.authorized?(controller, action, resource)
    @_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact

    return !!authorization_method unless authorization_method.respond_to?(:call)
    controller = controller.controller if controller.respond_to?(:controller)

    begin
      !!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
    rescue *@_exceptions
      false
    end
  end

  def self.authorize!(controller, action, resource)
    raise Effective::AccessDenied.new('Access Denied', action, resource) unless authorized?(controller, action, resource)
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
effective_resources-0.8.15 lib/effective_resources.rb
effective_resources-0.8.14 lib/effective_resources.rb
effective_resources-0.8.13 lib/effective_resources.rb
effective_resources-0.8.12 lib/effective_resources.rb
effective_resources-0.8.11 lib/effective_resources.rb
effective_resources-0.8.10 lib/effective_resources.rb
effective_resources-0.8.9 lib/effective_resources.rb
effective_resources-0.8.8 lib/effective_resources.rb
effective_resources-0.8.7 lib/effective_resources.rb