Sha256: f094830e52c64e14c1c7a31c5e3ccc3e81cdad1fb6092a56648fdc07629f815f

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 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)
        types = types & ::CanTango.config.accounts.registered
        accounts = types.map do |type|
          meth = :"current_#{type}_account"
          send(meth) if respond_to?(meth) && (types.empty? || types.include?(type))
        end
        chosen_account = accounts.compact.first
        chosen_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.3 lib/cantango/api/session/account.rb
cantango-api-0.1.2 lib/cantango/api/session/account.rb