Sha256: a50c71919360d469f719e70db23ecce69c50400e96c0a56af95706dd863d384f

Contents?: true

Size: 963 Bytes

Versions: 60

Compression:

Stored size: 963 Bytes

Contents

require 'inline_svg'
require 'effective_bootstrap/engine'
require 'effective_bootstrap/version'

module EffectiveBootstrap

  # 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

60 entries across 60 versions & 1 rubygems

Version Path
effective_bootstrap-0.4.6 lib/effective_bootstrap.rb
effective_bootstrap-0.4.5 lib/effective_bootstrap.rb
effective_bootstrap-0.4.4 lib/effective_bootstrap.rb
effective_bootstrap-0.4.3 lib/effective_bootstrap.rb
effective_bootstrap-0.4.2 lib/effective_bootstrap.rb
effective_bootstrap-0.4.1 lib/effective_bootstrap.rb
effective_bootstrap-0.4.0 lib/effective_bootstrap.rb
effective_bootstrap-0.3.22 lib/effective_bootstrap.rb
effective_bootstrap-0.3.21 lib/effective_bootstrap.rb
effective_bootstrap-0.3.20 lib/effective_bootstrap.rb
effective_bootstrap-0.3.19 lib/effective_bootstrap.rb
effective_bootstrap-0.3.18 lib/effective_bootstrap.rb
effective_bootstrap-0.3.17 lib/effective_bootstrap.rb
effective_bootstrap-0.3.16 lib/effective_bootstrap.rb
effective_bootstrap-0.3.15 lib/effective_bootstrap.rb
effective_bootstrap-0.3.14 lib/effective_bootstrap.rb
effective_bootstrap-0.3.13 lib/effective_bootstrap.rb
effective_bootstrap-0.3.12 lib/effective_bootstrap.rb
effective_bootstrap-0.3.11 lib/effective_bootstrap.rb
effective_bootstrap-0.3.10 lib/effective_bootstrap.rb