pry 0.9.6-i386-mingw32 → 0.9.6.1-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - ree
6
+ - rbx-2.0
7
+ - jruby
8
+
9
+ notifications:
10
+ irc: "irc.freenode.org#pry"
11
+ recipients:
12
+ - jrmair@gmail.com
13
+
14
+ branches:
15
+ only:
16
+ - master
data/README.markdown CHANGED
@@ -1,7 +1,8 @@
1
+ [![Build Status](https://secure.travis-ci.org/pry/pry.png)](http://travis-ci.org/pry/pry)
1
2
  <center>
2
3
  ![Alt text](http://dl.dropbox.com/u/26521875/pry_logo_350.png)
3
4
 
4
- (C) John Mair (banisterfiend) 2011
5
+ (C) John Mair (banisterfiend) 2011<br>
5
6
 
6
7
 
7
8
  **Please** [DONATE](http://www.pledgie.com/campaigns/15899) to the Pry project - Pry was a **huge** amount of work and every donation received is encouraging and supports Pry's continued development!
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rake/clean'
2
- require 'rake/gempackagetask'
2
+ require "rubygems"
3
+ require "rubygems/package_task"
3
4
 
4
5
  $:.unshift 'lib'
5
6
  require 'pry/version'
@@ -26,8 +27,12 @@ def apply_spec_defaults(s)
26
27
  s.add_dependency("method_source",">=0.6.5")
27
28
  s.add_development_dependency("bacon",">=1.1.0")
28
29
  s.add_development_dependency("open4", "~>1.0.1")
30
+ s.add_development_dependency("rake", "~>0.9")
29
31
  end
30
32
 
33
+ desc "Set up and run tests"
34
+ task :default => [:test]
35
+
31
36
  desc "Run tests"
32
37
  task :test do
33
38
  sh "bacon -Itest -rubygems -a -q"
@@ -49,7 +54,7 @@ namespace :ruby do
49
54
  s.platform = Gem::Platform::RUBY
50
55
  end
51
56
 
52
- Rake::GemPackageTask.new(spec) do |pkg|
57
+ Gem::PackageTask.new(spec) do |pkg|
53
58
  pkg.need_zip = false
54
59
  pkg.need_tar = false
55
60
  end
@@ -69,7 +74,7 @@ namespace :jruby do
69
74
  s.platform = "java"
70
75
  end
71
76
 
72
- Rake::GemPackageTask.new(spec) do |pkg|
77
+ Gem::PackageTask.new(spec) do |pkg|
73
78
  pkg.need_zip = false
74
79
  pkg.need_tar = false
75
80
  end
@@ -84,7 +89,7 @@ end
84
89
  s.platform = "i386-#{v}"
85
90
  end
86
91
 
87
- Rake::GemPackageTask.new(spec) do |pkg|
92
+ Gem::PackageTask.new(spec) do |pkg|
88
93
  pkg.need_zip = false
89
94
  pkg.need_tar = false
90
95
  end
data/lib/pry.rb CHANGED
@@ -173,6 +173,9 @@ if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/
173
173
  end
174
174
 
175
175
  require "pry/version"
176
+ require "pry/rbx_method"
177
+ require "pry/rbx_path"
178
+ require "pry/method"
176
179
  require "pry/history_array"
177
180
  require "pry/helpers"
178
181
  require "pry/history"
@@ -9,6 +9,7 @@ class Pry
9
9
  # give it a nice inspect
10
10
  def VOID_VALUE.inspect() "void" end
11
11
 
12
+ attr_accessor :command_name
12
13
  attr_accessor :output
13
14
  attr_accessor :target
14
15
  attr_accessor :target_self
@@ -11,6 +11,8 @@ class Pry
11
11
  class Command < Struct.new(:name, :description, :options, :block)
12
12
 
13
13
  def call(context, *args)
14
+ context.command_name = options[:listing]
15
+
14
16
  if stub_block = options[:stub_info]
15
17
  context.instance_eval(&stub_block)
16
18
  else
@@ -28,17 +28,15 @@ class Pry
28
28
  end
29
29
 
30
30
  command "reload-method", "Reload the source file that contains the specified method" do |meth_name|
31
- if (meth = get_method_object(meth_name, target, {})).nil?
32
- output.puts "Invalid method name: #{meth_name}."
33
- next
34
- end
31
+ meth = get_method_or_print_error(meth_name, target, {}, :omit_help)
32
+ next unless meth
35
33
 
36
- if is_a_c_method?(meth)
34
+ if meth.source_type == :c
37
35
  output.puts "Error: Can't reload a C method."
38
- elsif is_a_dynamically_defined_method?(meth)
36
+ elsif meth.dynamically_defined?
39
37
  output.puts "Error: Can't reload an eval method."
40
38
  else
41
- file_name = meth.source_location.first
39
+ file_name = meth.source_file
42
40
  load file_name
43
41
  output.puts "Reloaded #{file_name}."
44
42
  end
@@ -136,8 +136,11 @@ class Pry
136
136
  i_num = 5
137
137
  end
138
138
 
139
- meth_name = meth_name_from_binding(target)
140
- meth_name = "N/A" if !meth_name
139
+ if (meth = Pry::Method.from_binding(target))
140
+ meth_name = meth.name
141
+ else
142
+ meth_name = "N/A"
143
+ end
141
144
 
142
145
  if file =~ /(\(.*\))|<.*>/ || file == "" || file == "-e"
143
146
  output.puts "Cannot find local context. Did you use `binding.pry` ?"
@@ -32,20 +32,15 @@ class Pry
32
32
 
33
33
  args = [nil] if args.empty?
34
34
  args.each do |method_name|
35
- meth_name = method_name
36
- if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
37
- output.puts "Invalid method name: #{meth_name}. Type `show-doc --help` for help"
38
- next
39
- end
35
+ meth = get_method_or_print_error(method_name, target, opts.to_hash(true))
36
+ next unless meth
40
37
 
41
- doc, code_type = doc_and_code_type_for(meth)
42
- next if !doc
38
+ next output.puts("No documentation found.") if meth.doc.nil? || meth.doc.empty?
43
39
 
44
- next output.puts("No documentation found.") if doc.empty?
45
- doc = process_comment_markup(doc, code_type)
46
- output.puts make_header(meth, code_type, doc)
47
- output.puts "#{text.bold("visibility: ")} #{method_visibility(meth).to_s}"
48
- output.puts "#{text.bold("signature: ")} #{signature_for(meth)}"
40
+ doc = process_comment_markup(meth.doc, meth.source_type)
41
+ output.puts make_header(meth, doc)
42
+ output.puts "#{text.bold("visibility: ")} #{meth.visibility}"
43
+ output.puts "#{text.bold("signature: ")} #{meth.signature}"
49
44
  output.puts
50
45
  render_output(opts.flood?, false, doc)
51
46
  doc
@@ -76,26 +71,20 @@ class Pry
76
71
 
77
72
  next if opts.help?
78
73
 
79
- meth_name = args.shift
80
- if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
81
- output.puts "Invalid method name: #{meth_name}. Type `stat --help` for help"
82
- next
83
- end
84
-
85
- if !is_a_c_method?(meth) && !is_a_dynamically_defined_method?(meth)
86
- set_file_and_dir_locals(path_line_for(meth).first)
87
- end
88
-
89
- output.puts "Method Information:"
90
- output.puts "--"
91
- output.puts "Name: " + meth_name
92
- output.puts "Owner: " + (meth.owner.to_s ? meth.owner.to_s : "Unknown")
93
- output.puts "Visibility: " + method_visibility(meth).to_s
94
- output.puts "Type: " + (meth.is_a?(Method) ? "Bound" : "Unbound")
95
- output.puts "Arity: " + meth.arity.to_s
96
- output.puts "Method Signature: " + signature_for(meth)
97
-
98
- output.puts "Source location: " + (meth.source_location ? meth.source_location.join(":") : "Not found.")
74
+ meth = get_method_or_print_error(args.shift, target, opts.to_hash(true))
75
+ next unless meth
76
+
77
+ output.puts unindent <<-EOS
78
+ Method Information:
79
+ --
80
+ Name: #{meth.name}
81
+ Owner: #{meth.owner ? meth.owner : "Unknown"}
82
+ Visibility: #{meth.visibility}
83
+ Type: #{meth.is_a?(Method) ? "Bound" : "Unbound"}
84
+ Arity: #{meth.arity}
85
+ Method Signature: #{meth.signature}
86
+ Source Location: #{meth.source_location ? meth.source_location.join(":") : "Not found."}
87
+ EOS
99
88
  end
100
89
 
101
90
  command "gist-method", "Gist a method to github. Type `gist-method --help` for more info.", :requires_gem => "gist" do |*args|
@@ -122,19 +111,17 @@ class Pry
122
111
 
123
112
  next if opts.help?
124
113
 
125
- # This needs to be extracted into its own method as it's shared
126
- # by show-method and show-doc and stat commands
127
- meth_name = args.shift
128
- if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
129
- output.puts "Invalid method name: #{meth_name}. Type `gist-method --help` for help"
130
- next
131
- end
114
+ meth = get_method_or_print_error(args.shift, target, opts.to_hash(true))
115
+ next unless meth
132
116
 
133
117
  type_map = { :ruby => "rb", :c => "c", :plain => "plain" }
134
118
  if !opts.doc?
135
- content, code_type = code_and_code_type_for(meth)
119
+ content = meth.source
120
+ code_type = meth.source_type
136
121
  else
137
- content, code_type = doc_and_code_type_for(meth)
122
+ content = meth.doc
123
+ code_type = meth.source_type
124
+
138
125
  text.no_color do
139
126
  content = process_comment_markup(content, code_type)
140
127
  end
@@ -147,44 +134,6 @@ class Pry
147
134
 
148
135
  output.puts "Gist created at #{link}"
149
136
  end
150
-
151
- helpers do
152
-
153
- # paraphrased from awesome_print gem
154
- def signature_for(method)
155
- if method.respond_to?(:parameters)
156
-
157
- args = method.parameters.inject([]) do |arr, (type, name)|
158
- name ||= (type == :block ? 'block' : "arg#{arr.size + 1}")
159
- arr << case type
160
- when :req then name.to_s
161
- when :opt, :rest then "*#{name}"
162
- when :block then "&#{name}"
163
- else '?'
164
- end
165
- end
166
- else
167
- args = (1..method.arity.abs).map { |i| "arg#{i}" }
168
- args[-1] = "*#{args[-1]}" if method.arity < 0
169
- end
170
-
171
- "#{method.name}(#{args.join(', ')})"
172
- end
173
-
174
- def method_visibility(meth)
175
- if meth.owner.public_instance_methods.include? meth.name
176
- :public
177
- elsif meth.owner.protected_instance_methods.include? meth.name
178
- :protected
179
- elsif meth.owner.private_instance_methods.include? meth.name
180
- :private
181
- else
182
- :none
183
- end
184
- end
185
- end
186
-
187
137
  end
188
-
189
138
  end
190
139
  end
@@ -77,17 +77,13 @@ class Pry
77
77
 
78
78
  if opts.m?
79
79
  meth_name = opts[:m]
80
- if (meth = get_method_object(meth_name, target, {})).nil?
81
- output.puts "Invalid method name: #{meth_name}."
82
- next
83
- end
84
- code, _ = code_and_code_type_for(meth)
85
- next if !code
80
+ meth = get_method_or_print_error(meth_name, target, {}, :omit_help)
81
+ next unless meth and meth.source
86
82
 
87
83
  range = opts.l? ? one_index_range_or_number(opts[:l]) : (0..-1)
88
84
  range = (0..-2) if opts.o?
89
85
 
90
- eval_string << Array(code.each_line.to_a[range]).join
86
+ eval_string << Array(meth.source.each_line.to_a[range]).join
91
87
  elsif opts.f?
92
88
  file_name = File.expand_path(opts[:f])
93
89
  next output.puts "No such file: #{opts[:f]}" if !File.exists?(file_name)
@@ -28,33 +28,28 @@ class Pry
28
28
  output.puts opt
29
29
  end
30
30
  end
31
-
32
31
  next if opts.help?
32
+ opts[:instance] = opts['instance-methods'] if opts.m?
33
33
 
34
34
  args = [nil] if args.empty?
35
35
  args.each do |method_name|
36
- meth_name = method_name
37
- if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
38
- output.puts "Invalid method name: #{meth_name}. Type `show-method --help` for help"
39
- next
40
- end
41
-
42
- code, code_type = code_and_code_type_for(meth)
43
- next if !code
36
+ meth = get_method_or_print_error(method_name, target, opts.to_hash(true))
37
+ next unless meth and meth.source
44
38
 
45
- output.puts make_header(meth, code_type, code)
39
+ output.puts make_header(meth)
46
40
  if Pry.color
47
- code = CodeRay.scan(code, code_type).term
41
+ code = CodeRay.scan(meth.source, meth.source_type).term
42
+ else
43
+ code = meth.source
48
44
  end
49
45
 
50
46
  start_line = false
51
- if opts.l?
52
- start_line = meth.source_location ? meth.source_location.last : 1
47
+ if opts.b?
48
+ start_line = 1
49
+ elsif opts.l?
50
+ start_line = meth.source_line || 1
53
51
  end
54
52
 
55
- start_line = opts.b? ? 1 : start_line
56
-
57
-
58
53
  render_output(opts.flood?, start_line, code)
59
54
  code
60
55
  end
@@ -89,23 +84,25 @@ class Pry
89
84
  end
90
85
 
91
86
  if find_command(command_name)
92
- block = find_command(command_name).block
87
+ block = Pry::Method.new(find_command(command_name).block)
93
88
 
94
- code, _ = code_and_code_type_for(block)
95
- next if !code
89
+ next unless block.source
90
+ set_file_and_dir_locals(block.source_file)
96
91
 
97
- output.puts make_header(block, :ruby, code)
92
+ output.puts make_header(block)
98
93
 
99
94
  if Pry.color
100
- code = CodeRay.scan(code, :ruby).term
95
+ code = CodeRay.scan(block.source, :ruby).term
96
+ else
97
+ code = block.source
101
98
  end
102
99
 
103
100
  start_line = false
104
101
  if opts.l?
105
- start_line = block.source_location ? block.source_location.last : 1
102
+ start_line = block.source_line || 1
106
103
  end
107
104
 
108
- render_output(opts.flood?, opts.l? ? block.source_location.last : false, code)
105
+ render_output(opts.flood?, opts.l? ? block.source_line : false, code)
109
106
  code
110
107
  else
111
108
  output.puts "No such command: #{command_name}."
@@ -115,13 +112,14 @@ class Pry
115
112
  command "edit", "Invoke the default editor on a file. Type `edit --help` for more info" do |*args|
116
113
  opts = Slop.parse!(args) do |opt|
117
114
  opt.banner unindent <<-USAGE
118
- Usage: edit [--no-reload|--reload] [--line LINE] [--temp|--ex|FILE[:LINE]]
115
+ Usage: edit [--no-reload|--reload] [--line LINE] [--temp|--ex|FILE[:LINE]|--in N]
119
116
  Open a text editor. When no FILE is given, edits the pry input buffer.
120
117
  Ensure #{text.bold("Pry.config.editor")} is set to your editor of choice.
121
118
  e.g: edit sample.rb
122
119
  USAGE
123
120
 
124
121
  opt.on :e, :ex, "Open the file that raised the most recent exception (_ex_.file)", :optional => true, :as => Integer
122
+ opt.on :i, :in, "Open a temporary file containing the specified line of _in_.", :optional => true, :as => Integer
125
123
  opt.on :t, :temp, "Open an empty temporary file"
126
124
  opt.on :l, :line, "Jump to this line in the opened file", true, :as => Integer
127
125
  opt.on :n, :"no-reload", "Don't automatically reload the edited code"
@@ -141,6 +139,8 @@ class Pry
141
139
 
142
140
  content = if opts.t?
143
141
  ""
142
+ elsif opts.i?
143
+ _pry_.input_array[opts[:i] || -1] || ""
144
144
  elsif eval_string.strip != ""
145
145
  eval_string
146
146
  else
@@ -168,8 +168,8 @@ class Pry
168
168
  bt_index = opts[:ex].to_i
169
169
 
170
170
  ex_file, ex_line = ex.bt_source_location_for(bt_index)
171
- if ex_file && is_core_rbx_path?(ex_file)
172
- file_name = rbx_convert_path_to_full(ex_file)
171
+ if ex_file && RbxPath.is_core_path?(ex_file)
172
+ file_name = RbxPath.convert_path_to_full(ex_file)
173
173
  else
174
174
  file_name = ex_file
175
175
  end
@@ -221,7 +221,6 @@ class Pry
221
221
  output.puts opt
222
222
  end
223
223
  end
224
-
225
224
  next if opts.help?
226
225
 
227
226
  if !Pry.config.editor
@@ -230,21 +229,14 @@ class Pry
230
229
  next
231
230
  end
232
231
 
233
- meth_name = args.shift
234
- meth_name, target, type = get_method_attributes(meth_name, target, opts.to_hash(true))
235
- meth = get_method_object_from_target(meth_name, target, type)
236
-
237
- if meth.nil?
238
- output.puts "Invalid method name: #{meth_name}."
239
- next
240
- end
232
+ meth = get_method_or_print_error(args.shift, target, opts.to_hash(true))
233
+ next unless meth
241
234
 
242
- if opts.p? || is_a_dynamically_defined_method?(meth)
243
- code, _ = code_and_code_type_for(meth)
235
+ if opts.p? || meth.dynamically_defined?
236
+ lines = meth.source.lines.to_a
244
237
 
245
- lines = code.lines.to_a
246
238
  if lines[0] =~ /^def [^( \n]+/
247
- lines[0] = "def #{meth_name}#{$'}"
239
+ lines[0] = "def #{meth.name}#{$'}"
248
240
  else
249
241
  next output.puts "Error: Pry can only patch methods created with the `def` keyword."
250
242
  end
@@ -258,11 +250,10 @@ class Pry
258
250
  next
259
251
  end
260
252
 
261
- if is_a_c_method?(meth)
253
+ if meth.source_type == :c
262
254
  output.puts "Error: Can't edit a C method."
263
255
  else
264
- file, line = path_line_for(meth)
265
- set_file_and_dir_locals(file)
256
+ file, line = meth.source_file, meth.source_line
266
257
 
267
258
  invoke_editor(file, opts["no-jump"] ? 0 : line)
268
259
  silence_warnings do