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