Ruby 如何设计交互式程序?

Ruby 如何设计交互式程序?,ruby,mongodb,login,interactive,Ruby,Mongodb,Login,Interactive,我想设计一个交互式登录程序,以下是工作流程: def login(username, password) // 1. get login url // 2. check captcha has_captcha = check_captcha() // deal with captcha if necessary if has_captcha // 3. return captcha to client // 4. I sho

我想设计一个交互式登录程序,以下是工作流程:

def login(username, password)
    // 1. get login url

    // 2. check captcha
    has_captcha = check_captcha()

    // deal with captcha if necessary
    if has_captcha
       // 3. return captcha to client
       // 4. I should wait until user input the captcha
    end

    // 5. finally, post login
end
我的问题是在步骤3和步骤4,我的方法是:

  • 服务器
    将验证码写入mongodb并在那里等待
  • 客户端
    检查mongodb数据是否每5秒更新一次
  • 服务器
    还将每隔5秒检查一次mongodb,如果服务器发现mongodb已被客户端更新,则从mongodb获取客户端数据,继续登录

  • 但这并不是那么优雅,我如何轻松实现它?

    使用RejectionDB而不是Mongo,它具有即时推出机制。@mudasobwa如果我不使用任何数据库,我有选择吗?::客户端侦听推送和发送到服务器的邮件。@mudasobwa您的回答确实给了我一个提示,但您能给我一个非常简单的示例吗?我对此不太熟悉。