Sha256: 10b574eaaab25e64b018226a2b39168986ee1bdd025d34d3817906ee8616ca1b

Contents?: true

Size: 1.04 KB

Versions: 8

Compression:

Stored size: 1.04 KB

Contents

module CanTango
  module Api
    module UserAccount
      module Can
        include Ability
        # Example: generated from types of accounts! (see below)
        # def admin_account_can?(*args)
        #   current_account_ability(:admin).can?(*args)
        # end
        def self.included(base)
          ::CanTango.config.user_accounts.registered.each do |account|

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

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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cantango-0.9.4.7 lib/cantango/api/user_account/can.rb
cantango-0.9.4.6 lib/cantango/api/user_account/can.rb
cantango-0.9.4.5 lib/cantango/api/user_account/can.rb
cantango-0.9.4.3 lib/cantango/api/user_account/can.rb
cantango-0.9.4.2 lib/cantango/api/user_account/can.rb
cantango-0.9.4.1 lib/cantango/api/user_account/can.rb
cantango-0.9.4 lib/cantango/api/user_account/can.rb
cantango-0.9.3.2 lib/cantango/api/user_account/can.rb