I am building an application which subclasses Sinatra like so:
require 'rubygems'
require 'sinatra/base'
require 'sinatra/assetpack'
class App < Sinatra::Base
...
run!
end
How can I access irb? Options are not parsed when executing sinatra this way, how do I programmatically open an irb shell?
I'm a little confused whether you want to open an IRB session from within your app (?) or use IRB to debug your Sinatra project?
For debugging Rack-based apps (such as Sinatra), I like using the racksh gem, which "is like script/console in Rails" for Rack applications. Its main advantage over IRB is that racksh loads the entire application environment into the shell, making debugging a breeze.
From racksh's Github page: "It's purpose is to allow developer to introspect his application and/or make some initial setup. You can for example run DataMapper.auto_migrate! or make a request to /users/666 and check response details. It's mainly aimed at apps that don't have console-like component (ie. apps built with Sinatra) but all frameworks can benefit from interactive Rack stack and request introspection."
However, racksh requires your app to have a
config.ru
file, so you would have to re-write your app:Then in your app folder (where config.ru resides):
Check this simple search interface for Microsoft's Bing using Sinatra and
binger
gem. If you follow the instructions from there you will understand better.First at all, create a Gemfile and add:
Then run the
bundle
command that will generatedGemfile.lock
. Then create aconfig.ru
file, and add by example:Your
app.rb
could look like this:You must have a folder named
views
. Createindex.erb
and add:Finally, run
rackup
.Source: https://github.com/thinkphp/sinatra-bing
Demo: http://sinatra-bing.herokuapp.com/
Just type as below (at the shell prompt):