我有一个脚本在从我的sinatra应用程序中调用脚本时查询第三方API,但我不希望它在我启动Thin服务器时运行。有没有办法阻止我的代码运行,直到我直接调用它?例如,我可以运行检查以查看我的服务器是否在ruby / sinatra中运行以防止我的代码运行?
# the following code is inside a class and gets initialized when my server launch script is executed
authToken = ENV['EVERNOTE_AUTH_TOKEN']
evernoteHost = "www.evernote.com"
userStoreUrl = "https://#{evernoteHost}/edam/user"
userStoreTransport = Thrift::HTTPClientTransport.new(userStoreUrl)
userStoreProtocol = Thrift::BinaryProtocol.new(userStoreTransport)
userStore = Evernote::EDAM::UserStore::UserStore::Client.new(userStoreProtocol)
# this line of code executes on server start
noteStoreUrl = userStore.getNoteStoreUrl(authToken)
看起来ruby在运行每个文件时都会进行语法检查,并且我的API在最后一行被我的意志调用,我想编写一个if语句,使其无法调用,除非我的服务器已经运行< / p>