Search code examples
iosdeviserubymotion

implement devise-like "current_user" method in RubyMotion App


I am an Objective C noob and learning to build apps with RubyMotion.

I want to be able to call current_user and get the currently logged in user to my app.

Right now I am sending the current_user record from the server and calling User.new(:user) when a user logs in, but I can't call this user globally the way I'd like to, and send it into a Formotion edit form, etc

Right now I am initializing models using the KVO as described in the ruby tutorial Should I implement MotionModel? How would I use that tool to get that ready-at-hand current_user method?

Thanks!


Solution

  • I usually use a class method in the user model.

    User.current_user
    

    Your user class:

    class User
    
      def self.current_user
        @current_user ||= begin
          # get your user here, using BubbleWrap's App::Persistence or another persistence mechanism.
        end
      end
    
    end