I use only one file for sinatra application (sinatra.rb) where I have a route:
get '/ajax2?' do
my_function()
end
Can I call my_function() from another ruby script (cron.rb) and passing all the params? So whatever code is in this route is executed the same way if I accessed it from a browser?
I need to call it from a cron job.
- ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
- sinatra (1.3.2)
- sinatra-advanced-routes (0.5.1)
- sinatra-reloader (0.5.0)
update:
pretty sure all you need is a module, like so, in my_module.rb:
then in your app.rb:
you you can require and include that module in your cron.rb
If I follow your question correctly (not sure I do), pull your code out into an extension, so your directory structure looks like this:
then in my_extension.rb:
and in app.rb all you should need is:
that’s the first step, then move the contents of your extension into a gem and you can require the gem in your Gemfile in any sinatra application.