/
irb.rb
56 lines (49 loc) · 1.33 KB
/
irb.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module Sinatra
# Sinatra Irb is entered via <tt>ruby myapp.rb -c</tt> (replace myapp.rb with your app filename)
#
# Be sure to also check out Sinatra::TestMethods for more cool stuff when your in Irb
#
module Irb
extend self
# taken from merb
def start! #:nodoc:
Object.send(:include, TestMethods) # added to allow post_to in console
Object.class_eval do
# Reload all Sinatra and App specific files
def reload!
Loader.reload!
end
# Show the +body+ with result info in your text editor!!! Great Job!
def show!(editor = nil)
editor = editor || ENV['EDITOR']
IO.popen(editor, 'w') do |f|
f.puts "<!--"
f.puts result_info
f.puts "-->"
f.puts
f.puts body
end
nil
end
alias :mate :show!
def result_info #:nodoc:
info = <<-end_info
# Status: #{status}
# Headers: #{headers.inspect}
end_info
end
end
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