Class: Lolita::Extensions::Authorization::CanCanAdapter
- Defined in:
- lib/lolita/extensions/authorization/cancan_adapter.rb
Instance Method Summary collapse
- #authorize!(*args) ⇒ Object
- #can?(*args) ⇒ Boolean
- #cannot?(*args) ⇒ Boolean
- #current_ability(*args) ⇒ Object
-
#initialize(context, options = {}) ⇒ CanCanAdapter
constructor
A new instance of CanCanAdapter.
Constructor Details
#initialize(context, options = {}) ⇒ CanCanAdapter
Returns a new instance of CanCanAdapter.
7 8 9 10 11 12 13 14 |
# File 'lib/lolita/extensions/authorization/cancan_adapter.rb', line 7 def initialize context, ={} raise NameError, "CanCan is not defined" unless defined?(CanCan) raise Lolita::NoAuthorizationDefinedError, "Lolita.authorization is not defined" unless Lolita. @context = context @options = current_ability end |
Instance Method Details
#authorize!(*args) ⇒ Object
32 33 34 |
# File 'lib/lolita/extensions/authorization/cancan_adapter.rb', line 32 def *args current_ability && @context && @context.(*args) || current_ability.(*args) end |
#can?(*args) ⇒ Boolean
16 17 18 |
# File 'lib/lolita/extensions/authorization/cancan_adapter.rb', line 16 def can? *args current_ability.can?(*args) end |
#cannot?(*args) ⇒ Boolean
20 21 22 |
# File 'lib/lolita/extensions/authorization/cancan_adapter.rb', line 20 def cannot? *args current_ability.cannot?(*args) end |
#current_ability(*args) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/lolita/extensions/authorization/cancan_adapter.rb', line 24 def current_ability *args unless @current_ability @current_ability = Lolita.ability_class.new(@options[:current_user]) @context && @context.instance_variable_set(:"@current_ability",@current_ability) end @current_ability end |