Module: CanTango::Api::UserAccount::Can

Includes:
Ability
Defined in:
lib/cantango/api/user_account/can.rb

Class Method Summary collapse

Methods included from Ability

#current_account_ability, #user_account_ability

Methods included from Options

#ability_options, options_list, #options_list

Methods included from Common

#category, #create_ability

Class Method Details

.included(base) ⇒ Object

Example: generated from types of accounts! (see below) def admin_account_can?(*args)

(:admin).can?(*args)

end



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cantango/api/user_account/can.rb', line 10

def self.included(base)
  ::CanTango.config.user_accounts.registered.each do ||

    # by default alias call to current_xxx_account to current_xxx (devise user method) unless already defined!
    unless base.methods.include? :"current_#{}_account"
      define_method :"current_#{}_account" do
        send :"current_#{}"
      end
    end

    base.class_eval %{
      def #{}_account_can? *args
        current_account_ability(:#{}).can?(*args)
      end

      def #{}_account_cannot? *args
        current_account_ability(:#{}).cannot?(*args)
      end
     }
  end
end