docs
[sinatra.git] / lib / sinatra / irb.rb
blob76d0473c73982c1e9e03f60a183e4ebfe95592fe
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         end
32         alias :mate :show!
33         
34         def result_info #:nodoc:
35           info = <<-end_info
36           # Status: #{status}
37           # Headers: #{headers.inspect}
38           end_info
39         end
40       end
41       
42       ARGV.clear # Avoid passing args to IRB 
43       require 'irb' 
44       require 'irb/completion' 
45       def exit
46         exit!
47       end   
48       if File.exists? ".irbrc"
49         ENV['IRBRC'] = ".irbrc"
50       end
51       IRB.start
52       exit!
53     end
54   end
55 end