Class: Lolita::Extensions::Authorization::CanCanAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/lolita/extensions/authorization/cancan_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(context, options = {}) ⇒ CanCanAdapter

Returns a new instance of CanCanAdapter.

Raises:

  • (NameError)


7
8
9
10
11
12
13
14
# File 'lib/lolita/extensions/authorization/cancan_adapter.rb', line 7

def initialize context, options={}
  raise NameError, "CanCan is not defined" unless defined?(CanCan)
  raise Lolita::NoAuthorizationDefinedError, "Lolita.authorization is not defined" unless Lolita.authorization
  @context = context
  @options = options
  set_default_options
  current_ability
end

Instance Method Details

#authorize!(*args) ⇒ Object



32
33
34
# File 'lib/lolita/extensions/authorization/cancan_adapter.rb', line 32

def authorize! *args
  current_ability && @context && @context.authorize!(*args) || current_ability.authorize!(*args)
end

#can?(*args) ⇒ Boolean

Returns:

  • (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

Returns:

  • (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