Module: Cannie::ControllerExtensions

Extended by:
ActiveSupport::Concern
Defined in:
lib/cannie/controller_extensions.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#can?(action, on: nil) ⇒ Boolean

Checks whether passed action is permitted for passed subject

can? :index, on: :entries

or

can? :index, on: EntriesController

or

can? :index, on: 'admin/entries'

Parameters:

  • action (Symbol)
  • controller (Object)

    class or controller_path as a string or symbol

Returns:

  • (Boolean)

    result of checking permission

Raises:



59
60
61
62
# File 'lib/cannie/controller_extensions.rb', line 59

def can?(action, on: nil)
  raise Cannie::SubjectNotSetError, 'Subject should be specified' unless on
  current_permissions.can?(action, on)
end

#current_permissionsObject



68
69
70
# File 'lib/cannie/controller_extensions.rb', line 68

def current_permissions
  @current_permissions ||= ::Permissions.new(current_user)
end

#permitted?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/cannie/controller_extensions.rb', line 64

def permitted?
  !!@_permitted
end