Sha256: 367a5630ea138c1811967aeb19cb43241f8b545d38858e7e27f4dd97c69beaaa

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

module CanTango::Api
  module Session
    module Account
      def self.included(base)
        ::CanTango.config.accounts.registered.each do |type|
          base.class_eval %{
            def session_#{type}_account
              current_#{type}_account if respond_to? :current_#{type}_account
              guest_account
            end
          }
        end
      end

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

      def guest_account
        CanTango.config.guest.account
      end
      
      def active_account
        session[:active_account]
      end

      def active_account= account
        session[:active_account] = account
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cantango-api-0.1.1 lib/cantango/api/session/account.rb
cantango-api-0.1.0 lib/cantango/api/session/account.rb