irt 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -64,7 +64,7 @@ first, then if you want more details you can read this documentation.
64
64
 
65
65
  ### Command/Directives Usage
66
66
 
67
- >> irt_help
67
+ >> irt_help # in an irt session
68
68
 
69
69
  ## Colored and Styled Output
70
70
 
@@ -79,7 +79,7 @@ IRT uses colors consistently, so you will have an instant feedback about what a
79
79
  - __blue__ for the Virtual Log, Rails Log and generic labels
80
80
  - __yellow__ for result echo (not setting last value), for binding sessions and for tests with diffs
81
81
  - __green__ for result echo (setting last value) (and object 'b' in a diff)
82
- - __red__ for erros, exceptions and rerun
82
+ - __red__ for errors, exceptions and rerun
83
83
 
84
84
  Besides IRT is using reversed and bold styles to compose a more readable/graphical output.
85
85
 
@@ -105,7 +105,7 @@ to any existing file, irt will ask you to confirm that you want to create that f
105
105
  if you don't pass any path argument, irt will create a temporary one-empty-line file.
106
106
 
107
107
  Notice: When you pass a dir as the path, irt will recursively execute all the '.irt' files in it, so suffixing
108
- with '.irt' the files is not just a convention. It allows to skyp any non .irt file, like libraries or files
108
+ with '.irt' the files is not just a convention. It allows to skip any non .irt file, like libraries or files
109
109
  used with the 'insert\_file' directive.
110
110
 
111
111
  #### Note about new files
@@ -166,8 +166,8 @@ that's not relevant for your code so the typo and the error doesn't get recorded
166
166
  When you just inspect a variable, using p, pp, ap, puts, y, ... or use any irt command...
167
167
  that are not relevant steps that you want to rerun the next time, so they don't get recorded in the log.
168
168
 
169
- Also , if you are in an inspecting or binding session,
170
- that stesps are not relevant for your tests, so they don't get recorded in the log.
169
+ Also, if you are in an inspecting or binding session,
170
+ that steps are not relevant for your tests, so they don't get recorded in the log.
171
171
 
172
172
  ### Log Management
173
173
 
@@ -201,7 +201,7 @@ When you type 'tt' irt serializes the current (last) value returned by the last
201
201
  and adds one test statement to your log. If you paste the log in the irt file,
202
202
  you will have it executed the next time you will run the file.
203
203
 
204
- Your tipical testing cycle with IRT is:
204
+ Your typical testing cycle with IRT is:
205
205
 
206
206
  - write/change some code in your IDE
207
207
  - run it with irt and check some value from your code
@@ -216,7 +216,7 @@ a very complex object.
216
216
  Besides, when a test fails IRT can show you the tail of the running file, (use 'l' or configure
217
217
  IRT.tail_on_irt = true for automatic tail) so you have an instant feedback about where the
218
218
  failure comes from. It also opens an interactive session at that point with all
219
- the variables loaded, so you can imediately and interactively try and fix what went wrong.
219
+ the variables loaded, so you can immediately and interactively try and fix what went wrong.
220
220
 
221
221
  If you want to edit the running file, just type 'nano' or 'vi' without any argument and you will open
222
222
  the file at the current line. Edit, save and exit from the editor, and you will continue your session
@@ -304,7 +304,7 @@ to play with your variables and methods during execution (see Binding Sessions)
304
304
 
305
305
  ### Object diff
306
306
 
307
- IRT can compare complex objects and shows the diffs. You can run 'vdiff obj_a, obj_b'
307
+ IRT can compare complex objects and shows the diffs. You can run 'vdiff obj_a, obj_b' (or 'vd obj_a, obj_b')
308
308
  and have a nice and easy to check graphical diff report of the yaml dump of the 2 objects
309
309
 
310
310
  ### Kernel#capture
@@ -337,9 +337,9 @@ in place editing command to open the file at the line.
337
337
 
338
338
  ### Inspecting libs
339
339
 
340
- 'pp', 'yaml' (and 'ap' if installed) are loaded, so you can use 'pp', 'ap' and 'y' commands to have
341
- a better looking inspection of your objects. Besides they are also enhanced a bit: when invoked
342
- with no arguments, they use the last value (\_) as the default (e.g. just type 'y' instead 'y \_')
340
+ 'pp' and 'yaml' are loaded, so you can use 'pp' and 'y' commands to have
341
+ a better looking inspection of your objects. Besides 'p', 'pp', 'y' and 'ap' (if you require it in the .irtrc file)
342
+ are also enhanced a bit: when invoked with no arguments, they use the last value (\_) as the default (e.g. just type 'y' instead 'y \_')
343
343
 
344
344
  ### In place inspecting/editing of backtraced files
345
345
 
@@ -459,7 +459,7 @@ and the prompt is '#>' instead '=>'. Example:
459
459
 
460
460
  ### File insert/eval
461
461
 
462
- You can split your tests and reuse them in other files as you whould do with 'partials' template files.
462
+ You can split your tests and reuse them in other files as you would do with 'partials' template files.
463
463
  Use "insert_file 'file/path'" to insert a file into another. It will be evaluated by IRT as
464
464
  it were written right in the including file itself. Take that into account with variables and last_values.
465
465
  Besides, you should NOT suffix them with '.irt', so they will get ignored by the irt executable scanning the dirs.
@@ -483,6 +483,9 @@ play well with IRT, then copy and paste just part of it.
483
483
  You can also change the configuration options in the ~/.irtrc file. The following are the defaults
484
484
  which should work quite well without any change:
485
485
 
486
+ # uncomment if you want to use the awesome_print gem
487
+ # require 'ap'
488
+
486
489
  # set this to true if your prompt get messed up when you use the history
487
490
  # IRT.fix_readline_prompt = false
488
491
 
@@ -509,7 +512,7 @@ which should work quite well without any change:
509
512
  # IRT.nano_command_format = %(nano +%2$d "%1$s")
510
513
 
511
514
  # the format to build the command to launch vi
512
- # IRT.vi_command_format = %(vi -c "startinsert" "%1$s" +%2$d)
515
+ # IRT.vi_command_format = %(vi "%1$s" +%2$d)
513
516
 
514
517
  # the format to build the command to launch the ri tool
515
518
  # if RUBY_VERSION < 1.9.2 uses qri (from fastri) else bri
@@ -568,13 +571,13 @@ worring about requiring them from your test files.
568
571
 
569
572
  For example:
570
573
 
571
- working_dir
574
+ working_dir/
572
575
  irt_helper.rb #1
573
- first_level
576
+ first_level/
574
577
  irt_helper.rb #2
575
578
  testA.irt
576
579
  testB.irt
577
- second_level
580
+ second_level/
578
581
  irt_helper.rb #3
579
582
  test1.irt
580
583
  test2.irt
@@ -584,15 +587,17 @@ irt_helper.rb #1, #2 and #3. If you are running the testA.irt and testB.irt, IRT
584
587
  require the irt_helper.rb #1, #2. But if you run the same from the first_level dir, the irt_helper.rb #1
585
588
  will not be loaded, so be careful to be in the right dir to make it work properly.
586
589
 
587
- ### Rails
590
+ ## Rails
588
591
 
589
592
  You can use irt instead of the standard Rails console, by just calling the irt executable from
590
- any Rails application dir. By default IRT will output the rails log (colored in blue) right in the console.
593
+ any Rails application dir. If you want to skip the autoloading of the Rails app even from that
594
+ dir, you must pass the -n option (--no-rails).
591
595
 
596
+ By default IRT will output the rails log (colored in blue) right in the console.
592
597
  You can switch the rails log ON or OFF by using the 'rails\_log\_on' (or 'rlo') and 'rails\_log\_off' (or 'rlf')
593
598
  commands in any session, besides you can set the option IRT.rails_log to true or false in the ~/.irtrc file.
594
599
 
595
- #### Rails 3
600
+ ### Rails 3
596
601
 
597
602
  You must add the gem to your Gemfile, to make the bundler happy:
598
603
 
@@ -603,7 +608,7 @@ it will ask and eventually add it for you.
603
608
 
604
609
  ## Known Issue
605
610
 
606
- IRT use yaml serialization, and inherits its limits (e.g.: Yaml cannot dump anonymous classes, MatchData, oject that contains binding, etc.)
611
+ IRT uses yaml serialization, and inherits its limits (e.g.: Yaml cannot dump anonymous classes, MatchData, object that contains binding, etc.)
607
612
  so if you stumble upon on one of them, you have just to test the subparts of the object that you cannot dump. For example, instead of testing one whole anonymous
608
613
  class, (which is however a bad idea) you can add tests for the values returned by its methods or variables.
609
614
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.6
1
+ 1.1.7
data/bin/irt CHANGED
@@ -7,6 +7,12 @@ require 'optparse'
7
7
  require 'prompter'
8
8
  require 'dye'
9
9
 
10
+ prompter = Prompter.new do |pr|
11
+ def pr.say_echo(result, opts={})
12
+ out = sprintf " #> %s", result
13
+ say out, :style => :yellow
14
+ end
15
+ end
10
16
 
11
17
  version = File.read(File.expand_path('../../VERSION', __FILE__)).strip
12
18
 
@@ -24,7 +30,7 @@ Usage:
24
30
  Options:
25
31
  EOB
26
32
 
27
- options[:interactive_eof]
33
+ options[:interactive_eof] = false
28
34
  opts.on( '-i', '--interactive-eof', 'Opens an interactive session at EOF') do
29
35
  options[:interactive_eof] = true
30
36
  end
@@ -35,10 +41,15 @@ EOB
35
41
  end
36
42
 
37
43
  options[:rails_env] = 'development'
38
- opts.on( '-r', '--rails-env [ENVIRONMENT]', 'Sets the Rails Environment' ) do |env|
44
+ opts.on( '-e', '--rails-env [ENVIRONMENT]', 'Sets the Rails Environment' ) do |env|
39
45
  options[:rails_env] = env
40
46
  end
41
47
 
48
+ options[:no_rails] = false
49
+ opts.on( '-n', '--no-rails', 'Does not autoload the Rails Environment' ) do
50
+ options[:no_rails] = true
51
+ end
52
+
42
53
  opts.on( '-v', '--version', 'Shows the version and exits' ) do
43
54
  puts version
44
55
  exit
@@ -61,14 +72,25 @@ paths = if ARGV.empty?
61
72
  tmp_file = Tempfile.new(['', '.irt'])
62
73
  tmp_file << "\n" # one empty line makes irb of 1.9.2 happy
63
74
  tmp_file.flush
64
- [ tmp_file.path ]
75
+ tmp_path = tmp_file.path
76
+ at_exit do
77
+ require 'irt/utils'
78
+ if File.read(tmp_path).length > 1
79
+ prompter.yes? %(The template file has been modified, do you want to save it?) do
80
+ prompter.choose %(Enter the file path to save:), /[\w0-9_]/ do |as_file|
81
+ IRT::Utils.save_as(tmp_path, as_file, prompter){ system(ENV['IRT_COMMAND']) }
82
+ end
83
+ end
84
+ end
85
+ end
86
+ [ tmp_path ]
65
87
  else
66
88
  ARGV.map {|p| File.expand_path(p) }
67
89
  end
68
90
 
69
91
  files = paths.map do |path|
70
92
  unless File.exists?(path)
71
- next if Prompter.no? %(Do you want to create the file "#{path}"?), :hint => '[<enter=y|n]', :default => 'y'
93
+ next if prompter.no? %(Do you want to create the file "#{path}"?), :hint => '[<enter=y|n]', :default => 'y'
72
94
  options[:interactive_eof] = true
73
95
  dirname = File.dirname(path)
74
96
  FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
@@ -78,16 +100,16 @@ files = paths.map do |path|
78
100
  end.flatten
79
101
 
80
102
  if files.empty?
81
- Prompter.say_notice 'No *.irt files to run'
103
+ prompter.say_notice 'No *.irt files to run'
82
104
  exit
83
105
  end
84
106
 
85
- cmd_format = if File.exists?('./config/environment.rb')
107
+ cmd_format = if File.exists?('./config/environment.rb') && !options[:no_rails]
86
108
  if File.exists?('./script/rails')
87
109
  gemfile = File.read('Gemfile')
88
110
  unless gemfile.match(/\bgem\b.+\birt\b/)
89
- Prompter.say_warning %(The Gemfile doesn't look to include any 'gem "irt"' statement.\nIRT will probably not work until you add it!)
90
- Prompter.yes?("Do you want to add irt to your Gemfile?", :hint => '[enter=y|n]', :default => 'y') do
111
+ prompter.say_warning %(The Gemfile doesn't look to include any 'gem "irt"' statement.\nIRT will probably not work until you add it!)
112
+ prompter.yes?("Do you want to add irt to your Gemfile?", :hint => '[enter=y|n]', :default => 'y') do
91
113
  File.open('Gemfile', 'a') do |f|
92
114
  f.puts %(gem "irt")
93
115
  end
data/irtrc CHANGED
@@ -1,3 +1,6 @@
1
+ # uncomment if you want to use the awesome_print gem
2
+ # require 'ap'
3
+
1
4
  # IRT RC file
2
5
  # ITR conf options
3
6
 
@@ -27,7 +30,7 @@
27
30
  # IRT.nano_command_format = %(nano +%2$d "%1$s")
28
31
 
29
32
  # the format to build the command to launch vi
30
- # IRT.vi_command_format = %(vi -c "startinsert" "%1$s" +%2$d)
33
+ # IRT.vi_command_format = %(vi "%1$s" +%2$d)
31
34
 
32
35
  # the format to build the command to launch the ri tool
33
36
  # if RUBY_VERSION < 1.9.2 uses qri (from fastri) else bri
data/lib/irt.rb CHANGED
@@ -50,7 +50,7 @@ module IRT
50
50
  Dye.color = bool
51
51
  end
52
52
 
53
- def init
53
+ def init_config
54
54
  @session_no = 0
55
55
  @differ = IRT::Differ
56
56
  @irt_on_diffs = true
@@ -91,18 +91,30 @@ module IRT
91
91
  'gnome-open %1$s'
92
92
  end
93
93
  end
94
- @vi_command_format = %(vi -c "startinsert" "%1$s" +%2$d)
94
+ @vi_command_format = %(vi "%1$s" +%2$d)
95
95
  @nano_command_format = %(nano +%2$d "%1$s")
96
96
  @ri_command_format = IRT::RubyVersion >= '1.9.2' ? %(bri "%s") : %(qri -f #{Dye.color? ? 'ansi' : 'plain'} "%s")
97
97
  @debug = false
98
98
  end
99
99
 
100
- def init_files
100
+ def before_run
101
101
  @irt_file = IRB.conf[:SCRIPT]
102
102
  require 'irt/extensions/rails' if defined?(ActiveSupport::BufferedLogger)
103
103
  @log = Log.new
104
104
  @log.print_running_file
105
105
  IRT::Directives.load_helper_files
106
+ IRB::ExtendCommandBundle.class_eval do
107
+ [:p, :y, :pp, :ap].each do |m|
108
+ next unless begin
109
+ method(m)
110
+ rescue NameError
111
+ end
112
+ define_method(m) do |*args|
113
+ args = [context.last_value] if args.empty?
114
+ super *args
115
+ end
116
+ end
117
+ end
106
118
  end
107
119
 
108
120
  def lib_path
@@ -20,13 +20,6 @@ module IRT
20
20
  end
21
21
  alias_method :open_session, :irt # legacy method
22
22
 
23
- [:p, :y, :pp, :ap].each do |m|
24
- define_method(m) do |*args|
25
- args = [context.last_value] if args.empty?
26
- super *args
27
- end
28
- end
29
-
30
23
  def vdiff(a,b)
31
24
  puts IRT::Differ.new(a,b, :value, {:a_marker => 'a',
32
25
  :b_marker => 'b',
@@ -45,13 +45,8 @@ module IRT
45
45
  alias_method :tt, :add_test
46
46
 
47
47
  def save_as(path)
48
- path = File.expand_path(path)
49
- if File.exists?(path)
50
- return if IRT.prompter.no? %(Do you want to overwrite "#{path}"?), :hint => '[y|<enter=n]', :default => 'n'
51
- end
52
- cp IRT.irt_file, path
53
- ENV['IRT_COMMAND'] = ENV['IRT_COMMAND'].sub(/#{Regexp.quote(IRT.irt_file)}/, path)
54
- rerun
48
+ require 'irt/utils'
49
+ IRT::Utils.save_as(IRT.irt_file, path, IRT.prompter){ rerun }
55
50
  end
56
51
  alias_method :sa, :save_as
57
52
 
@@ -11,7 +11,7 @@ module IRB #:nodoc:
11
11
 
12
12
  def IRB.setup(ap_path=nil)
13
13
  irb_setup(ap_path)
14
- IRT.init_files
14
+ IRT.before_run
15
15
  end
16
16
 
17
17
  def IRB.init_config(ap_path)
@@ -35,12 +35,7 @@ module IRB #:nodoc:
35
35
  @CONF[:AT_EXIT] << proc{ print "\e[0m" if Dye.color? } # reset colors
36
36
  @CONF[:RC_NAME_GENERATOR] = proc {|rc| File.expand_path '~/.irtrc' }
37
37
 
38
- IRT.init
39
- end
40
-
41
- def IRB.irb_exit(irb, ret)
42
- IRT::Session.exit
43
- throw :IRB_EXIT, ret
38
+ IRT.init_config
44
39
  end
45
40
 
46
41
  end
@@ -12,7 +12,7 @@ class Method
12
12
  end
13
13
  arr = Array.new(n)
14
14
  set_trace_func proc{ |event, file, line, meth_name, binding, classname|
15
- if event.eql?('call') && name.match(meth_name.to_s)
15
+ if event.eql?('call') && name.to_s.match(meth_name.to_s)
16
16
  f = file
17
17
  l = line
18
18
  set_trace_func nil
data/lib/irt/session.rb CHANGED
@@ -27,6 +27,8 @@ module IRT
27
27
  IRT.log.status << [new_context.irb_name, mode]
28
28
  IRT.log.print_status unless mode == :file
29
29
  catch(:IRB_EXIT) { new_context.irb.eval_input }
30
+ ensure
31
+ IRT::Session.exit
30
32
  end
31
33
 
32
34
  def exit
data/lib/irt/utils.rb ADDED
@@ -0,0 +1,22 @@
1
+ module IRT
2
+ module Utils
3
+
4
+ extend self
5
+
6
+ def save_as(file, as_file_local, prompter)
7
+ as_file = File.expand_path(as_file_local)
8
+ if File.exists?(as_file)
9
+ return false if prompter.no? %(Do you want to overwrite "#{as_file}"?), :hint => '[y|<enter=n]', :default => 'n'
10
+ end
11
+ dirname = File.dirname(as_file)
12
+ FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
13
+ FileUtils.cp file, as_file
14
+ if prompter.yes? %(Do you want to run the file "#{as_file_local}" now?)
15
+ ENV['IRT_COMMAND'] = ENV['IRT_COMMAND'].sub(/#{Regexp.quote(file)}/, as_file)
16
+ yield
17
+ end
18
+ true
19
+ end
20
+
21
+ end
22
+ end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 1
9
- - 6
10
- version: 1.1.6
4
+ prerelease:
5
+ version: 1.1.7
11
6
  platform: ruby
12
7
  authors:
13
8
  - Domizio Demichelis
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-02-07 00:00:00 -04:00
13
+ date: 2011-02-10 00:00:00 -04:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,11 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 25
30
- segments:
31
- - 0
32
- - 1
33
- - 1
34
24
  version: 0.1.1
35
25
  type: :runtime
36
26
  version_requirements: *id001
@@ -42,11 +32,6 @@ dependencies:
42
32
  requirements:
43
33
  - - ">="
44
34
  - !ruby/object:Gem::Version
45
- hash: 25
46
- segments:
47
- - 0
48
- - 1
49
- - 1
50
35
  version: 0.1.1
51
36
  type: :runtime
52
37
  version_requirements: *id002
@@ -58,29 +43,18 @@ dependencies:
58
43
  requirements:
59
44
  - - ">="
60
45
  - !ruby/object:Gem::Version
61
- hash: 31
62
- segments:
63
- - 0
64
- - 1
65
- - 2
66
46
  version: 0.1.2
67
47
  type: :runtime
68
48
  version_requirements: *id003
69
49
  - !ruby/object:Gem::Dependency
70
- name: fastri
50
+ name: bri
71
51
  prerelease: false
72
52
  requirement: &id004 !ruby/object:Gem::Requirement
73
53
  none: false
74
54
  requirements:
75
55
  - - ">="
76
56
  - !ruby/object:Gem::Version
77
- hash: 81
78
- segments:
79
- - 0
80
- - 3
81
- - 1
82
- - 1
83
- version: 0.3.1.1
57
+ version: 0.1.5
84
58
  type: :runtime
85
59
  version_requirements: *id004
86
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.
@@ -129,6 +103,7 @@ files:
129
103
  - lib/irt/log.rb
130
104
  - lib/irt/ruby_version.rb
131
105
  - lib/irt/session.rb
106
+ - lib/irt/utils.rb
132
107
  has_rdoc: true
133
108
  homepage: http://github.com/ddnexus/irt
134
109
  licenses: []
@@ -143,25 +118,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
118
  requirements:
144
119
  - - ">="
145
120
  - !ruby/object:Gem::Version
146
- hash: 3
147
- segments:
148
- - 0
149
121
  version: "0"
150
122
  required_rubygems_version: !ruby/object:Gem::Requirement
151
123
  none: false
152
124
  requirements:
153
125
  - - ">="
154
126
  - !ruby/object:Gem::Version
155
- hash: 23
156
- segments:
157
- - 1
158
- - 3
159
- - 6
160
127
  version: 1.3.6
161
128
  requirements: []
162
129
 
163
130
  rubyforge_project:
164
- rubygems_version: 1.3.7
131
+ rubygems_version: 1.5.0
165
132
  signing_key:
166
133
  specification_version: 3
167
134
  summary: Interactive Ruby Tools - Improved irb and rails console with a lot of easy and powerful tools.