Module: Cannie::ControllerExtensions
- Defined in:
- lib/cannie/controller_extensions.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#can?(action, on: nil) ⇒ Boolean
Checks whether passed action is permitted for passed subject.
- #current_permissions ⇒ Object
- #permitted? ⇒ Boolean
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'
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 .can?(action, on) end |
#current_permissions ⇒ Object
67 68 69 |
# File 'lib/cannie/controller_extensions.rb', line 67 def @current_permissions ||= ::Permissions.new(current_user) end |
#permitted? ⇒ Boolean
63 64 65 |
# File 'lib/cannie/controller_extensions.rb', line 63 def permitted? !!@_permitted end |