Module: CanTango::Api::Session::Account
- Defined in:
- lib/cantango/api/session/account.rb
Class Method Summary collapse
Instance Method Summary collapse
- #active_account ⇒ Object
- #active_account=(account) ⇒ Object
-
#any_account(*types) ⇒ Object
give me any logged in user or the guest user.
- #guest_account ⇒ Object
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_account ⇒ Object
31 32 33 |
# File 'lib/cantango/api/session/account.rb', line 31 def active_account session[:active_account] end |
#active_account=(account) ⇒ Object
35 36 37 |
# File 'lib/cantango/api/session/account.rb', line 35 def active_account= account session[:active_account] = 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 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 |
#guest_account ⇒ Object
27 28 29 |
# File 'lib/cantango/api/session/account.rb', line 27 def guest_account CanTango.config.guest.account end |