Module: Allowy::Context
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/allowy/context.rb
Overview
This module provides the default and common context for checking the permissions. It is mixed into controllers in Rails by default and provides an easy way to reuse it in other parts of the application (RSpec, Cucumber or standalone). For example, you can use this code in your Cucumber features:
@example
class CucumberContext
include Allowy::Context
attr_accessor :current_user
def initialize(user)
@current_user = user
end
And then you can easily check the permissions like so:
@example
CucumberContext.new(that_user).can?(:create, Blog)
CucumberContext.new(that_user).should be_able_to :create, Blog
Instance Method Summary collapse
- #allowy_context ⇒ Object
- #authorize!(action, subject, *args) ⇒ Object
- #can?(action, subject, *args) ⇒ Boolean
- #cannot?(action, subject, *args) ⇒ Boolean
- #current_allowy ⇒ Object
Instance Method Details
#allowy_context ⇒ Object
26 27 28 |
# File 'lib/allowy/context.rb', line 26 def allowy_context self end |
#authorize!(action, subject, *args) ⇒ Object
42 43 44 |
# File 'lib/allowy/context.rb', line 42 def (action, subject, *args) current_allowy.access_control_for!(subject).(action, subject, *args) end |
#can?(action, subject, *args) ⇒ Boolean
34 35 36 |
# File 'lib/allowy/context.rb', line 34 def can?(action, subject, *args) current_allowy.access_control_for!(subject).can?(action, subject, *args) end |
#cannot?(action, subject, *args) ⇒ Boolean
38 39 40 |
# File 'lib/allowy/context.rb', line 38 def cannot?(action, subject, *args) current_allowy.access_control_for!(subject).cannot?(action, subject, *args) end |