Module: CanTango::Api::Session::Account

Defined in:
lib/cantango/api/session/account.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


4
5
6
7
8
9
10
11
12
13
# File 'lib/cantango/api/session/account.rb', line 4

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

Instance Method Details

#active_accountObject


31
32
33
# File 'lib/cantango/api/session/account.rb', line 31

def 
  session[:active_account]
end

#active_account=(account) ⇒ Object


35
36
37
# File 'lib/cantango/api/session/account.rb', line 35

def active_account= 
  session[:active_account] = 
end

#any_account(*types) ⇒ Object

give me any logged in user or the guest user


16
17
18
19
20
21
22
23
24
25
# File 'lib/cantango/api/session/account.rb', line 16

def  *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
   = accounts.compact.first
   || 
end

#guest_accountObject


27
28
29
# File 'lib/cantango/api/session/account.rb', line 27

def 
  CanTango.config.guest.
end