pry 0.9.1-i386-mswin32 → 0.9.2-i386-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,9 +1,15 @@
1
+ 21/6/2011 version 0.9.2
2
+ * fixed string interpolation bug (caused valid ruby code not to execute, sorry!)
3
+ * fixed `ls` command, so it can properly display members of Object and classes, and BasicObject, etc
4
+ * added a few git related commands to experimental command set, blame and diff
5
+
1
6
  17/6/2011 version 0.9.0
2
7
  * plugin system
3
8
  * regex commands
4
9
  * show-method works on methods defined in REPL
5
10
  * new command system/API
6
11
  * rubinius core support
12
+ * more backports to ruby 1.8
7
13
  * inp/out special locals
8
14
  * _ex_ backtrace navigation object (_ex_.line, _ex_.file)
9
15
  * readline history saving/loading
@@ -16,6 +22,8 @@
16
22
  * much more comprehensive test suite
17
23
  * support for new and old rubygems API
18
24
  * changed -s behaviour of ls (now excludes Object methods)
25
+ * removed eval-file, lls, lcd, and a few other commands
26
+
19
27
 
20
28
  26/3/2011 version 0.7.6.1
21
29
  * added slightly better support for YARD
@@ -62,7 +62,7 @@ class Pry
62
62
  # so early exit.
63
63
  begin
64
64
  interp_val = interpolate_string(val, target)
65
- rescue NameError
65
+ rescue Exception
66
66
  next
67
67
  end
68
68
 
@@ -4,11 +4,19 @@ class Pry
4
4
  Ls = Pry::CommandSet.new do
5
5
 
6
6
  helpers do
7
- def trim_methods(options, visibility)
8
- if options[:e]
7
+ def should_trim?(target, options)
8
+ if target.eval('self').is_a? Module
9
+ options[:e] || target.eval('self') >= Object
10
+ else
11
+ options[:e]
12
+ end
13
+ end
14
+
15
+ def trim_methods(target, options, visibility)
16
+ if should_trim?(target, options)
9
17
  []
10
18
  else
11
- Object.send("#{visibility}_methods")
19
+ Object.send("#{visibility}_instance_methods")
12
20
  end
13
21
  end
14
22
  end
@@ -73,7 +81,7 @@ Shows local and instance variables by default.
73
81
  options[:s] = true
74
82
  end
75
83
 
76
- opts.on("-e", "--everything", "Include superclass entries including Object (relevant to constant and methods options).") do
84
+ opts.on("-e", "--everything", "Include superclass entries including Object (must be combined with -s switch).") do
77
85
  options[:e] = true
78
86
  end
79
87
 
@@ -140,19 +148,19 @@ Shows local and instance variables by default.
140
148
 
141
149
  info["global variables"] = [Array(target.eval("global_variables")).sort, i += 1] if options[:g] || options[:a]
142
150
 
143
- info["public methods"] = [Array(target.eval("public_methods(#{options[:s]})")).uniq.sort - trim_methods(options, :public), i += 1] if (options[:m] && options[:P]) || options[:a]
151
+ info["public methods"] = [Array(target.eval("public_methods(#{options[:s]})")).uniq.sort - trim_methods(target, options, :public), i += 1] if (options[:m] && options[:P]) || options[:a]
144
152
 
145
- info["protected methods"] = [Array(target.eval("protected_methods(#{options[:s]})")).sort - trim_methods(options, :protected), i += 1] if (options[:m] && options[:r]) || options[:a]
153
+ info["protected methods"] = [Array(target.eval("protected_methods(#{options[:s]})")).sort - trim_methods(target, options, :protected), i += 1] if (options[:m] && options[:r]) || options[:a]
146
154
 
147
- info["private methods"] = [Array(target.eval("private_methods(#{options[:s]})")).sort - trim_methods(options, :private), i += 1] if (options[:m] && options[:p]) || options[:a]
155
+ info["private methods"] = [Array(target.eval("private_methods(#{options[:s]})")).sort - trim_methods(target, options, :private), i += 1] if (options[:m] && options[:p]) || options[:a]
148
156
 
149
157
  info["just singleton methods"] = [Array(target.eval("methods(#{options[:s]})")).sort, i += 1] if (options[:m] && options[:j]) || options[:a]
150
158
 
151
- info["public instance methods"] = [Array(target.eval("public_instance_methods(#{options[:s]})")).uniq.sort - trim_methods(options, :public), i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:P]) || options[:a])
159
+ info["public instance methods"] = [Array(target.eval("public_instance_methods(#{options[:s]})")).uniq.sort - trim_methods(target, options, :public), i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:P]) || options[:a])
152
160
 
153
- info["protected instance methods"] = [Array(target.eval("protected_instance_methods(#{options[:s]})")).uniq.sort - trim_methods(options, :protected), i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:r]) || options[:a])
161
+ info["protected instance methods"] = [Array(target.eval("protected_instance_methods(#{options[:s]})")).uniq.sort - trim_methods(target, options, :protected), i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:r]) || options[:a])
154
162
 
155
- info["private instance methods"] = [Array(target.eval("private_instance_methods(#{options[:s]})")).uniq.sort - trim_methods(options, :private), i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:p]) || options[:a])
163
+ info["private instance methods"] = [Array(target.eval("private_instance_methods(#{options[:s]})")).uniq.sort - trim_methods(target, options, :private), i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:p]) || options[:a])
156
164
 
157
165
  # dealing with 1.8/1.9 compatibility issues :/
158
166
  csuper = options[:s]
@@ -12,6 +12,66 @@ class Pry
12
12
  meth.reload
13
13
  end
14
14
 
15
+ command "blame", "Show blame for a method", :requires_gem => "grit" do |meth_name|
16
+ require 'grit'
17
+ if (meth = get_method_object(meth_name, target, {})).nil?
18
+ output.puts "Invalid method name: #{meth_name}."
19
+ next
20
+ end
21
+
22
+ repo ||= Grit::Repo.new(".")
23
+ start_line = meth.source_location.last
24
+ num_lines = meth.source.lines.count
25
+ authors = repo.blame(meth.source_location.first).lines.select do |v|
26
+ v.lineno >= start_line && v.lineno <= start_line + num_lines
27
+ end.map do |v|
28
+ v.commit.author.output(Time.new).split(/</).first.strip
29
+ end
30
+
31
+ lines_with_blame = []
32
+ meth.source.lines.zip(authors) { |line, author| lines_with_blame << ("#{author}".ljust(10) + colorize_code(line)) }
33
+ output.puts lines_with_blame.join
34
+ end
35
+
36
+ command "diff", "Show the diff for a method", :requires_gem => ["grit", "diffy"] do |meth_name|
37
+ require 'grit'
38
+ require 'diffy'
39
+
40
+ if (meth = get_method_object(meth_name, target, {})).nil?
41
+ output.puts "Invalid method name: #{meth_name}."
42
+ next
43
+ end
44
+
45
+ output.puts colorize_code(Diffy::Diff.new(method_code_from_head(meth), meth.source))
46
+ end
47
+
48
+ helpers do
49
+ def get_file_from_commit(path)
50
+ repo = Grit::Repo.new('.')
51
+ head = repo.commits.first
52
+ tree_names = path.split("/")
53
+ start_tree = head.tree
54
+ blob_name = tree_names.last
55
+ tree = tree_names[0..-2].inject(start_tree) { |a, v| a.trees.find { |t| t.basename == v } }
56
+ blob = tree.blobs.find { |v| v.basename == blob_name }
57
+ blob.data
58
+ end
59
+
60
+ def method_code_from_head(meth)
61
+ rel_path = relative_path(meth.source_location.first)
62
+ code = get_file_from_commit(rel_path)
63
+ start_line = meth.source_location.last
64
+ code_length = meth.source.lines.count
65
+ code.lines.to_a[(start_line - 1)...((start_line - 1) + code_length)].join
66
+ end
67
+
68
+ def relative_path(path)
69
+ path =~ /#{Regexp.escape(File.expand_path("."))}\/(.*)/
70
+ $1
71
+ end
72
+
73
+ end
74
+
15
75
  end
16
76
  end
17
77
  end
data/lib/pry/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Pry
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
data/test/test_pry.rb CHANGED
@@ -487,6 +487,15 @@ describe Pry do
487
487
  $test_interpolation = nil
488
488
  end
489
489
 
490
+ # bug fix for https://github.com/banister/pry/issues/170
491
+ it 'should not choke on complex string interpolation when checking if ruby code is a command' do
492
+ redirect_pry_io(InputTester.new('/#{Regexp.escape(File.expand_path("."))}/'), str_output = StringIO.new) do
493
+ pry
494
+ end
495
+
496
+ str_output.string.should.not =~ /SyntaxError/
497
+ end
498
+
490
499
  it 'should NOT interpolate ruby code into commands if :interpolate => false' do
491
500
  klass = Pry::CommandSet.new do
492
501
  command "hello", "", :keep_retval => true, :interpolate => false do |arg|
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pry
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.1
5
+ version: 0.9.2
6
6
  platform: i386-mswin32
7
7
  authors:
8
8
  - John Mair (banisterfiend)
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-17 00:00:00 Z
13
+ date: 2011-06-21 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ruby_parser