Sha256: a7a14fefe1bf74080e91468f24978539821cabe69cb11f72002e087788f2799d

Contents?: true

Size: 1.06 KB

Versions: 5

Compression:

Stored size: 1.06 KB

Contents

require 'effective_bootstrap'
require 'effective_resources'
require 'effective_datatables/engine'
require 'effective_datatables/version'

module EffectiveDatatables
  mattr_accessor :authorization_method

  mattr_accessor :default_length
  mattr_accessor :html_class

  mattr_accessor :actions_column # A Hash
  mattr_accessor :debug

  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) # Do the right thing with a view

    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 unless authorized?(controller, action, resource)
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
effective_datatables-4.0.4 lib/effective_datatables.rb
effective_datatables-4.0.3 lib/effective_datatables.rb
effective_datatables-4.0.2 lib/effective_datatables.rb
effective_datatables-4.0.1 lib/effective_datatables.rb
effective_datatables-4.0.0 lib/effective_datatables.rb