Module: EffectiveDatatables

Defined in:
lib/effective_datatables.rb,
lib/effective_datatables/engine.rb,
lib/effective_datatables/version.rb,
lib/generators/effective_datatables/install_generator.rb

Defined Under Namespace

Modules: Generators Classes: Engine

Constant Summary collapse

VERSION =
'4.4.4'.freeze

Class Method Summary collapse

Class Method Details

.authorize!(controller, action, resource) ⇒ Object



39
40
41
# File 'lib/effective_datatables.rb', line 39

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

.authorized?(controller, action, resource) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/effective_datatables.rb', line 26

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

.find(id) ⇒ Object



43
44
45
46
47
48
# File 'lib/effective_datatables.rb', line 43

def self.find(id)
  id = id.to_s.gsub(/-\d+\z/, '').gsub('-', '/')
  klass = (id.classify.safe_constantize || id.classify.pluralize.safe_constantize)

  klass.try(:new) || raise('unable to find datatable')
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



22
23
24
# File 'lib/effective_datatables.rb', line 22

def self.setup
  yield self
end