Module: CanTango::Api::User::Can

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

Class Method Summary collapse

Methods included from Ability

#current_user_ability, #user_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_can?(*args)

current_user_ability(:admin).can?(*args)

end



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cantango/api/user/can.rb', line 10

def self.included(base)
  ::CanTango.config.users.registered.each do |user|
    base.class_eval %{
      def #{user}_can? *args
        current_user_ability(:#{user}).can?(*args)
      end

      def #{user}_cannot? *args
        current_user_ability(:#{user}).cannot?(*args)
      end
     }
  end
end