1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Sexy IRB!!!

This commit is contained in:
blake.mizerany@gmail.com 2007-09-11 01:14:03 +00:00
parent 208158a7da
commit fb81823b8b
5 changed files with 69 additions and 27 deletions

23
lib/sinatra/irb.rb Normal file
View file

@ -0,0 +1,23 @@
module Sinatra
module Irb
extend self
# taken from merb
def start!
Object.send(:include, TestMethods) # added to allow post_to in console
ARGV.clear # Avoid passing args to IRB
require 'irb'
require 'irb/completion'
def exit
exit!
end
if File.exists? ".irbrc"
ENV['IRBRC'] = ".irbrc"
end
IRB.start
exit!
end
end
end

View file

@ -6,6 +6,7 @@ module Sinatra
attr_with_default :port, 4567
attr_with_default :environment, :development
attr_with_default :console, nil
def parse!(args)
OptionParser.new do |opts|
@ -15,6 +16,9 @@ module Sinatra
opts.on '-e environment', 'Set the environment (default if development)' do |env|
@environment = env
end
opts.on '-c', '--console', 'Run in console mode' do
@console = true
end
opts.on '-h', '--help', '-?', 'Show this message' do
puts opts
exit!

View file

@ -10,6 +10,9 @@ module Sinatra
def start
begin
setup_environment
Irb.start! if Options.console
tail_thread = tail(Options.log_file)
Rack::Handler::Mongrel.run(Dispatcher.new, :Port => Options.port) do |server|
logger.info "== Sinatra has taken the stage on port #{server.port}!"

View file

@ -0,0 +1,38 @@
module Sinatra
module TestMethods
@response = nil unless defined?("@response")
def get_it(path)
request = Rack::MockRequest.new(Sinatra::Dispatcher.new)
@response = request.get path
end
def post_it(path)
request = Rack::MockRequest.new(Sinatra::Dispatcher.new)
@response = request.post path
end
def response
@response
end
def status
@response.status
end
def text
@response.body
end
alias :xml :text
alias :html :text
alias :body :text
def headers
@response.headers
end
end
end

View file

@ -11,31 +11,5 @@ end
Sinatra::Server.running = true
class Test::Unit::TestCase
def get_it(path)
request = Rack::MockRequest.new(Sinatra::Dispatcher.new)
@response = request.get path
end
def post_it(path)
request = Rack::MockRequest.new(Sinatra::Dispatcher.new)
@response = request.post path
end
def response
@response
end
def status
@response.status
end
def text
@response.body
end
def headers
@response.headers
end
include TestMethods
end