irt 1.2.0.p01 → 1.2.0.p02
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +38 -4
- data/VERSION +1 -1
- data/bin/irt +14 -8
- data/lib/irt/commands/core.rb +1 -1
- data/lib/irt/commands/help.rb +5 -9
- data/lib/irt/commands/test.rb +2 -2
- data/lib/irt/extensions/irb.rb +14 -1
- data/lib/irt/extensions/irb/commands.rb +1 -0
- data/lib/irt/extensions/rails.rb +14 -0
- data/lib/irt/history.rb +5 -0
- data/lib/irt/session.rb +0 -1
- data/lib/irt/utils.rb +18 -10
- metadata +7 -41
data/README.markdown
CHANGED
@@ -12,8 +12,9 @@ that will make your life a lot easier.
|
|
12
12
|
|
13
13
|
- clean colored output for easy reading
|
14
14
|
- 3 types of sessions: interactive, inspecting and binding
|
15
|
-
- irb opening from your code (or erb templates) as binding session
|
16
|
-
-
|
15
|
+
- irb/irt opening from your code (or erb templates) as a binding session
|
16
|
+
- irb/irt opening from inside the Rails Server window
|
17
|
+
- optional colored Rails log in the console
|
17
18
|
- contextual ri doc with completion
|
18
19
|
- recording of session steps with filtering
|
19
20
|
- easy testing based on recorded steps
|
@@ -225,6 +226,18 @@ If you want to edit the running file, just type 'nano' or 'vi' without any argu
|
|
225
226
|
the file at the current line. Edit, save and exit from the editor, and you will continue your session
|
226
227
|
from the point you left. You can also 'rerun' the same file (or 'rr') when you need to reload the whole code.
|
227
228
|
|
229
|
+
### Rerun vs restart
|
230
|
+
|
231
|
+
When you make any change in an irt file being evaluated you should perform a 'rerun' (or 'rr')
|
232
|
+
in order to see the effect of your change.
|
233
|
+
The 'rerun' command will exit from all the opened sessions, call the at_exit procs and rerun the same file
|
234
|
+
without reloading any library or required file. That is the fastest behaviour when your changes are limited to any irt file.
|
235
|
+
|
236
|
+
If you change some library in any required file and you wants to rerun the same file against the changes,
|
237
|
+
you need to 'restart' (or 'rs') the whole process, so all the required files will be re-evaluated
|
238
|
+
and your irt file will be rerun in the new context. That is notably slower in complex application, but guarantees
|
239
|
+
a fresh loaded environment.
|
240
|
+
|
228
241
|
## Editing Tools
|
229
242
|
|
230
243
|
### In Place Editing
|
@@ -590,21 +603,40 @@ irt_helper.rb #1, #2 and #3. If you are running the testA.irt and testB.irt, IRT
|
|
590
603
|
require the irt_helper.rb #1, #2. But if you run the same from the first_level dir, the irt_helper.rb #1
|
591
604
|
will not be loaded, so be careful to be in the right dir to make it work properly.
|
592
605
|
|
606
|
+
Notice: the irt helpers files are 'require'd (not 'load'ed). For that reason they are
|
607
|
+
suitable for adding constants, methods, require(s) that will be loaded only once.
|
608
|
+
If you change any irt helper you should 'restart (or 'rs') once before your changes get reloaded.
|
609
|
+
|
593
610
|
## Rails
|
594
611
|
|
595
612
|
You can use irt instead of the standard Rails console, by just calling the irt executable from
|
596
613
|
any Rails application dir. If you want to skip the autoloading of the Rails app even from that
|
597
614
|
dir, you must pass the -n option (--no-rails).
|
598
615
|
|
616
|
+
$ cd my_rails_app
|
617
|
+
|
618
|
+
# will use the test environment in sandbox mode
|
619
|
+
$ irt -b--sandbox -etest
|
620
|
+
|
621
|
+
# will open a normal irt console, skipping the rails app
|
622
|
+
$ irt -n
|
623
|
+
|
599
624
|
By default IRT will output the rails log (colored in blue) right in the console.
|
600
625
|
You can switch the rails log ON or OFF by using the 'rails\_log\_on' (or 'rlo') and 'rails\_log\_off' (or 'rlf')
|
601
626
|
commands in any session, besides you can set the option IRT.rails_log to true or false in the ~/.irtrc file.
|
602
627
|
|
628
|
+
## Rerun, restart, reload!-rerun
|
629
|
+
|
630
|
+
The 'rerun' (or 'rr') irt command in rails will also perform a 'reload!' first, so if you are in development mode
|
631
|
+
your changes will be reloaded, so the command should do what you need: if it doesn't you
|
632
|
+
should use the regular 'restart' (or 'rs') as the last resort. The 'restart' causes the Rails environment
|
633
|
+
to be fully reloaded, so it is slower, but guaranteed.
|
634
|
+
|
603
635
|
### Rails Server Sessions
|
604
636
|
|
605
637
|
The server sessions are a quick way to interact with your application while your server is running,
|
606
638
|
without the need to launch a the irt executable: you can do almost everything you can from a regular IRT session
|
607
|
-
launched from the irt executable.
|
639
|
+
launched from the irt executable, besides you have access to the server internals.
|
608
640
|
|
609
641
|
If you want to open a session from your Rails code or from a template while the server is running,
|
610
642
|
you don't have to use the IRT executable: you can just add an 'irt binding' statement where you want
|
@@ -627,7 +659,9 @@ you will be asked if you want to shutdown the server or open an IRT session.
|
|
627
659
|
Notice that the execution of the web response is halted until you exit from the session.
|
628
660
|
When you exit, the response process will be resumed, and the server will return to its normal behaviour.
|
629
661
|
|
630
|
-
Note: The Server Sessions are known to work with WEBrick and Mongrel (using Rack)
|
662
|
+
Note: The Server Sessions are known to work with WEBrick and Mongrel (using Rack).
|
663
|
+
WEBrick might spit some error closing an Interactive Session, while it is ok
|
664
|
+
with Binding Sessions. Mongrel works perfectly.
|
631
665
|
|
632
666
|
### Rails 3
|
633
667
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.0.
|
1
|
+
1.2.0.p02
|
data/bin/irt
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
at_exit{ Dye.print_reset_colors }
|
4
|
+
|
3
5
|
require 'rubygems'
|
4
6
|
require 'fileutils'
|
5
7
|
require 'optparse'
|
@@ -13,9 +15,12 @@ optparse = OptionParser.new do |opts|
|
|
13
15
|
|
14
16
|
opts.banner = <<EOB
|
15
17
|
Interactive Ruby Tools:
|
16
|
-
Improved irb and
|
18
|
+
Improved irb and Rails Console with lots of easy and powerful tools.
|
17
19
|
Usage:
|
18
|
-
irt [
|
20
|
+
irt [PATHS] [options]
|
21
|
+
Paths:
|
22
|
+
List of irt files and/or dirs containing irt files.
|
23
|
+
If PATHS is omitted IRT will create and run a temporary empty file.
|
19
24
|
Options:
|
20
25
|
EOB
|
21
26
|
|
@@ -25,7 +30,7 @@ EOB
|
|
25
30
|
end
|
26
31
|
|
27
32
|
options[:irb_options] = nil
|
28
|
-
opts.on( '-b', '--irb-options [OPTIONS]', 'Sets the irb or
|
33
|
+
opts.on( '-b', '--irb-options [OPTIONS]', 'Sets the irb or Rails Console options' ) do |opt|
|
29
34
|
options[:irb_options] = opt
|
30
35
|
end
|
31
36
|
|
@@ -58,7 +63,11 @@ puts copy
|
|
58
63
|
|
59
64
|
paths = if ARGV.empty?
|
60
65
|
options[:interactive_eof] = true
|
61
|
-
|
66
|
+
tmp_path = IRT::Utils.create_tmp_file do |as_file, tmp_path|
|
67
|
+
ENV['IRT_COMMAND'] = ENV['IRT_COMMAND'].sub(/#{Regexp.quote(tmp_path)}/, as_file)
|
68
|
+
exec ENV['IRT_COMMAND']
|
69
|
+
end
|
70
|
+
[ tmp_path ]
|
62
71
|
else
|
63
72
|
ARGV.map {|p| File.expand_path(p) }
|
64
73
|
end
|
@@ -103,8 +112,5 @@ ENV['IRT_INTERACTIVE_EOF'] = options[:interactive_eof].inspect if options[:inter
|
|
103
112
|
|
104
113
|
files.each do |file|
|
105
114
|
ENV['IRT_COMMAND'] = sprintf cmd_format, options[:irb_options], file, options[:rails_env]
|
106
|
-
unless system
|
107
|
-
puts Dye.sgr(:clear) if Dye.color?
|
108
|
-
exit(1)
|
109
|
-
end
|
115
|
+
exit(1) unless system ENV['IRT_COMMAND']
|
110
116
|
end
|
data/lib/irt/commands/core.rb
CHANGED
data/lib/irt/commands/help.rb
CHANGED
@@ -5,7 +5,7 @@ module IRT
|
|
5
5
|
def irt_help
|
6
6
|
ensure_session
|
7
7
|
puts %(
|
8
|
-
#{label "
|
8
|
+
#{label " Irt Help ", :log_color}
|
9
9
|
- The #{IRT.dye "Commands", :interactive_color, :bold} are methods generally available in any IRT session
|
10
10
|
- The #{IRT.dye "Directives", :file_color, :bold} are methods available in any file but not in IRT sessions
|
11
11
|
- The #{IRT.dye "Extensions", :log_color, :bold} are methods available anywhere
|
@@ -13,8 +13,8 @@ module IRT
|
|
13
13
|
#{label " Inspecting Commands ", :interactive_color}
|
14
14
|
irt object Opens an inspecting session into object
|
15
15
|
vdiff|vd obj_a, obj_b Prints the visual diff of the yaml dump of 2 objects
|
16
|
-
|
17
|
-
|
16
|
+
p, pp, ap, y When invoked with no arguments print the last_value
|
17
|
+
(e.g. just type 'y' instead 'y _')
|
18
18
|
|
19
19
|
#{label " Log Commands ", :interactive_color}
|
20
20
|
log|l [limit] Prints limit or 'tail_size' lines of the virtual log
|
@@ -50,16 +50,12 @@ module IRT
|
|
50
50
|
by automatically choosing the :_eql?, or :_yaml_eql?
|
51
51
|
method, depending on the type of the last value (_)
|
52
52
|
add_test|tt desc Like add_test but adds a 'desc' directive first'
|
53
|
-
save_as|sa path Saves the current irt file as path
|
53
|
+
save_as|sa path Saves the current irt file as path
|
54
54
|
|
55
55
|
#{label " FileUtils Commands ", :interactive_color}
|
56
56
|
All the FileUtils methods are availabe as IRT Commands
|
57
57
|
(e.g. pwd, touch, mkdir, mv, cp, rm, rm_rf, compare_files, ...)
|
58
58
|
|
59
|
-
#{label " Enhanced Commands ", :interactive_color}
|
60
|
-
p, pp, ap, y When invoked with no arguments print the last_value
|
61
|
-
(e.g. just type 'y' instead 'y _')
|
62
|
-
|
63
59
|
#{label " Documentation Commands ", :interactive_color}
|
64
60
|
ri to_search Search the ri doc for to_search (no quotes needed)
|
65
61
|
ri obj.any_method Search the method.owner ri doc for of any_method
|
@@ -82,7 +78,7 @@ module IRT
|
|
82
78
|
run file Run an irt file (exiting from the current sessions)
|
83
79
|
rerun|rr Reruns the current irt file (exiting from the
|
84
80
|
current sessions)
|
85
|
-
restart|
|
81
|
+
restart|rs Restart the executable, reload IRT (and Rails) and
|
86
82
|
rerun the current file
|
87
83
|
irt_help|hh Shows this screen
|
88
84
|
sh command Alias for system("command") (no quotes needed)
|
data/lib/irt/commands/test.rb
CHANGED
data/lib/irt/extensions/irb.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'irb'
|
2
|
+
require 'irb/ext/save-history.rb'
|
2
3
|
require 'irt/extensions/irb/context'
|
3
4
|
require 'irt/extensions/irb/commands'
|
4
5
|
|
@@ -16,7 +17,6 @@ module IRB #:nodoc:
|
|
16
17
|
|
17
18
|
def IRB.init_config(ap_path)
|
18
19
|
original_init_config(ap_path)
|
19
|
-
|
20
20
|
@CONF[:AP_NAME] = 'irt'
|
21
21
|
@CONF[:PROMPT][:IRT] = { :PROMPT_I => "%02n >> ",
|
22
22
|
:PROMPT_S => ' "> ',
|
@@ -34,8 +34,21 @@ module IRB #:nodoc:
|
|
34
34
|
if IRB.CurrentContext.irt_mode == :file && !IRT::Session.exit_all?} \
|
35
35
|
if !!ENV['IRT_INTERACTIVE_EOF']
|
36
36
|
@CONF[:AT_EXIT] << proc{ IRT::Directives.test_summary }
|
37
|
+
@CONF[:AT_EXIT] << proc{ IRT::History.save_history }
|
37
38
|
@CONF[:RC_NAME_GENERATOR] = proc {|rc| File.expand_path '~/.irtrc' }
|
39
|
+
end
|
40
|
+
|
38
41
|
|
42
|
+
module HistorySavingAbility
|
43
|
+
def HistorySavingAbility.extended(obj)
|
44
|
+
# save_history has to be called just one time at exit
|
45
|
+
# IRB.conf[:AT_EXIT].push proc{obj.save_history}
|
46
|
+
obj.load_history
|
47
|
+
obj
|
48
|
+
end
|
39
49
|
end
|
40
50
|
|
41
51
|
end
|
52
|
+
|
53
|
+
require 'irt/history'
|
54
|
+
|
data/lib/irt/extensions/rails.rb
CHANGED
data/lib/irt/history.rb
ADDED
data/lib/irt/session.rb
CHANGED
@@ -36,7 +36,6 @@ module IRT
|
|
36
36
|
IRT.log.print_status unless mode == :file
|
37
37
|
old_trap = trap('SIGINT'){new_context.irb.signal_handle}
|
38
38
|
catch(:IRB_EXIT) { new_context.irb.eval_input }
|
39
|
-
# rethrow if there is a parent context, and it is a reading file
|
40
39
|
begin throw(:IRB_EXIT) ; rescue ArgumentError ; end if @@exit_all
|
41
40
|
ensure
|
42
41
|
IRT::Session.exit unless @@exit_all
|
data/lib/irt/utils.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'irt/prompter'
|
2
2
|
|
3
3
|
module IRT
|
4
|
+
|
4
5
|
module Utils
|
5
6
|
|
6
7
|
extend self
|
@@ -11,31 +12,38 @@ module IRT
|
|
11
12
|
return if IRT.initialized
|
12
13
|
puts IRT::Utils.copyright
|
13
14
|
ARGV.clear
|
14
|
-
tmp_path =
|
15
|
+
tmp_path = if run
|
16
|
+
create_tmp_file {|as_file| IRT::Session.run_file as_file}
|
17
|
+
else
|
18
|
+
create_tmp_file
|
19
|
+
end
|
15
20
|
ARGV.push tmp_path
|
16
21
|
IRB.start
|
17
22
|
end
|
18
23
|
|
19
|
-
def create_tmp_file(
|
24
|
+
def create_tmp_file(&block)
|
20
25
|
require 'tempfile'
|
21
26
|
tmp_file = Tempfile.new(['', '.irt'])
|
22
27
|
tmp_file << "\n" # one empty line makes irb of 1.9.2 happy
|
23
28
|
tmp_file.flush
|
24
|
-
|
25
|
-
|
29
|
+
# ENV used because with IRT.cli? 2 different processes need to access the same path
|
30
|
+
ENV['IRT_TMP_PATH'] = tmp_path = tmp_file.path
|
31
|
+
at_exit { check_save_tmp_file(tmp_file, &block) }
|
26
32
|
tmp_path
|
27
33
|
end
|
28
34
|
|
29
|
-
def save_as(as_file_local,
|
35
|
+
def save_as(as_file_local, source_path=IRT.irt_file, &block)
|
30
36
|
as_file = File.expand_path(as_file_local)
|
31
37
|
if File.exists?(as_file)
|
32
38
|
return false if IRT::Prompter.no? %(Do you want to overwrite "#{as_file}"?), :hint => '[y|<enter=n]', :default => 'n'
|
33
39
|
end
|
34
40
|
dirname = File.dirname(as_file)
|
35
41
|
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
|
36
|
-
FileUtils.cp
|
37
|
-
if
|
38
|
-
|
42
|
+
FileUtils.cp source_path, as_file
|
43
|
+
if block && IRT::Prompter.yes?( %(Do you want to run the file "#{as_file_local}" now?) )
|
44
|
+
# reset the tmpfile content so the at_exit proc will not be triggered
|
45
|
+
File.open(source_path, 'w'){|f| f.puts "\n"} if IRT.irt_file == Pathname.new(ENV['IRT_TMP_PATH']).realpath
|
46
|
+
block.call as_file, source_path
|
39
47
|
end
|
40
48
|
end
|
41
49
|
|
@@ -49,11 +57,11 @@ module IRT
|
|
49
57
|
|
50
58
|
private
|
51
59
|
|
52
|
-
def check_save_tmp_file(tmp_file,
|
60
|
+
def check_save_tmp_file(tmp_file, &block)
|
53
61
|
if tmp_file.size > 1
|
54
62
|
IRT::Prompter.yes? %(The template file has been modified, do you want to save it?) do
|
55
63
|
IRT::Prompter.choose %(Enter the file path to save:), /[\w0-9_]/ do |as_file|
|
56
|
-
save_as(as_file,
|
64
|
+
save_as(as_file, tmp_file.path, &block)
|
57
65
|
end
|
58
66
|
end
|
59
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: irt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
- p01
|
11
|
-
version: 1.2.0.p01
|
4
|
+
prerelease: 6
|
5
|
+
version: 1.2.0.p02
|
12
6
|
platform: ruby
|
13
7
|
authors:
|
14
8
|
- Domizio Demichelis
|
@@ -16,7 +10,7 @@ autorequire:
|
|
16
10
|
bindir: bin
|
17
11
|
cert_chain: []
|
18
12
|
|
19
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-22 00:00:00 -04:00
|
20
14
|
default_executable:
|
21
15
|
dependencies:
|
22
16
|
- !ruby/object:Gem::Dependency
|
@@ -27,11 +21,6 @@ dependencies:
|
|
27
21
|
requirements:
|
28
22
|
- - ">="
|
29
23
|
- !ruby/object:Gem::Version
|
30
|
-
hash: 25
|
31
|
-
segments:
|
32
|
-
- 0
|
33
|
-
- 1
|
34
|
-
- 1
|
35
24
|
version: 0.1.1
|
36
25
|
type: :runtime
|
37
26
|
version_requirements: *id001
|
@@ -43,11 +32,6 @@ dependencies:
|
|
43
32
|
requirements:
|
44
33
|
- - ">="
|
45
34
|
- !ruby/object:Gem::Version
|
46
|
-
hash: 29
|
47
|
-
segments:
|
48
|
-
- 0
|
49
|
-
- 1
|
50
|
-
- 3
|
51
35
|
version: 0.1.3
|
52
36
|
type: :runtime
|
53
37
|
version_requirements: *id002
|
@@ -59,29 +43,18 @@ dependencies:
|
|
59
43
|
requirements:
|
60
44
|
- - ">="
|
61
45
|
- !ruby/object:Gem::Version
|
62
|
-
hash: 19
|
63
|
-
segments:
|
64
|
-
- 0
|
65
|
-
- 1
|
66
|
-
- 4
|
67
46
|
version: 0.1.4
|
68
47
|
type: :runtime
|
69
48
|
version_requirements: *id003
|
70
49
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
50
|
+
name: bri
|
72
51
|
prerelease: false
|
73
52
|
requirement: &id004 !ruby/object:Gem::Requirement
|
74
53
|
none: false
|
75
54
|
requirements:
|
76
55
|
- - ">="
|
77
56
|
- !ruby/object:Gem::Version
|
78
|
-
|
79
|
-
segments:
|
80
|
-
- 0
|
81
|
-
- 3
|
82
|
-
- 1
|
83
|
-
- 1
|
84
|
-
version: 0.3.1.1
|
57
|
+
version: 0.1.5
|
85
58
|
type: :runtime
|
86
59
|
version_requirements: *id004
|
87
60
|
description: If you use IRT in place of irb or rails console, you will have more tools that will make your life a lot easier.
|
@@ -125,6 +98,7 @@ files:
|
|
125
98
|
- lib/irt/extensions/method.rb
|
126
99
|
- lib/irt/extensions/object.rb
|
127
100
|
- lib/irt/extensions/rails.rb
|
101
|
+
- lib/irt/history.rb
|
128
102
|
- lib/irt/hunks.rb
|
129
103
|
- lib/irt/init.rb
|
130
104
|
- lib/irt/log.rb
|
@@ -146,25 +120,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
146
120
|
requirements:
|
147
121
|
- - ">="
|
148
122
|
- !ruby/object:Gem::Version
|
149
|
-
hash: 3
|
150
|
-
segments:
|
151
|
-
- 0
|
152
123
|
version: "0"
|
153
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
125
|
none: false
|
155
126
|
requirements:
|
156
127
|
- - ">="
|
157
128
|
- !ruby/object:Gem::Version
|
158
|
-
hash: 23
|
159
|
-
segments:
|
160
|
-
- 1
|
161
|
-
- 3
|
162
|
-
- 6
|
163
129
|
version: 1.3.6
|
164
130
|
requirements: []
|
165
131
|
|
166
132
|
rubyforge_project:
|
167
|
-
rubygems_version: 1.
|
133
|
+
rubygems_version: 1.5.0
|
168
134
|
signing_key:
|
169
135
|
specification_version: 3
|
170
136
|
summary: Interactive Ruby Tools - Improved irb and rails console with a lot of easy and powerful tools.
|