Sha256: 0746b88a20b4873e2bd7751d8b462a9b12ffd72191c74fdbecfa41e15c7d6b2d

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

module CanTango
  module Api
    module User
      module Session
        # Example: generated from types of accounts! (see below)
        # def admin_can?(*args)
        #   current_ability(:admin).can?(*args)
        # end

        def self.included(base)
          ::CanTango.config.users.registered.each do |user|
            base.class_eval %{
              def session_#{user}
                current_#{user} if respond_to? :current_#{user}
                guest_user
              end
            }
          end
        end

        # give me any logged in user or the guest user
        def any_user *types
          types = types.flatten.select_labels.map(&:to_sym)
          c_user = ::CanTango.config.users.registered.each do |user|
            meth = :"current_#{user}"
            send(meth) if respond_to?(meth) && (types.empty? || types.include?(user))
          end.compact.first
          c_user || guest_user
        end

        def guest_user
          CanTango.config.guest.user
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cantango-0.9.4.1 lib/cantango/api/user/session.rb
cantango-0.9.4 lib/cantango/api/user/session.rb
cantango-0.9.3.2 lib/cantango/api/user/session.rb