Module: CanTango::Api::User::Session

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



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

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

Instance Method Details

#any_user(*types) ⇒ Object

give me any logged in user or the guest user



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

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

#guest_userObject



26
27
28
# File 'lib/cantango/api/user/session.rb', line 26

def guest_user
  CanTango.config.guest.user
end