Module: Cannie::ControllerExtensions

Defined in:
lib/cannie/controller_extensions.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



3
4
5
6
7
# File 'lib/cannie/controller_extensions.rb', line 3

def self.extended(base)
  base.include self
  base.extend ClassMethods
  base.helper_method :can?, :current_permissions
end

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:



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

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

#current_permissionsObject



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

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

#permitted?Boolean

Returns:

  • (Boolean)


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

def permitted?
  !!@_permitted
end