Sha256: 4ec08eb88a4352083db463d38ecbe45879739b8ed2d1e78b45223cb9deedac1e

Contents?: true

Size: 1.27 KB

Versions: 14

Compression:

Stored size: 1.27 KB

Contents

module CanTango
  module Api
    module UserAccount
      module Ability
        def user_account_ability user_account, options = {}
          @current_ability ||= create_ability(user_account, ability_options.merge(options))
        end

        def current_account_ability user_type = :user
          account_meth = :"current_#{user_type}_account"
          return guest_user_account if !respond_to?(account_meth)

          user_account = send(account_meth)
          return guest_user_account if !user_account

          user_account_ability user_account
        end

        protected

        include CanTango::Api::Common

        def get_ability_user_acount user_type
          user_account_meth = :"current_#{user_type}_account"
          return AbilityAccount.guest if !respond_to?(user_account_meth)

          user_account = send user_account_meth
          user_account ? user_account : AbilityAccount.guest
        end

        module AbilityAccount
          def self.guest
            account = CanTango.config.guest.account

            raise "You must set the guest_account to a Proc or lambda in CanTango.config" if !account
            account.respond_to?(:call) ? account.call : account
          end
        end

        include CanTango::Api::Options
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
cantango-0.8.9.5 lib/cantango/api/user_account/ability.rb
cantango-0.8.9.4 lib/cantango/api/user_account/ability.rb
cantango-0.8.9.3 lib/cantango/api/user_account/ability.rb
cantango-0.8.9.2 lib/cantango/api/user_account/ability.rb
cantango-0.8.9.1 lib/cantango/api/user_account/ability.rb
cantango-0.8.9 lib/cantango/api/user_account/ability.rb
cantango-0.8.8.1 lib/cantango/api/user_account/ability.rb
cantango-0.8.8 lib/cantango/api/user_account/ability.rb
cantango-0.8.7 lib/cantango/api/user_account/ability.rb
cantango-0.8.6.2 lib/cantango/api/user_account/ability.rb
cantango-0.8.6.1 lib/cantango/api/user_account/ability.rb
cantango-0.8.6 lib/cantango/api/user_account/ability.rb
cantango-0.8.5.1 lib/cantango/api/user_account/ability.rb
cantango-0.8.0 lib/cantango/api/user_account/ability.rb