pry 0.10.2-i386-mswin32 → 1.0.0.pre1-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. data/.document +2 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +21 -0
  4. data/.yardopts +3 -0
  5. data/CHANGELOG +503 -0
  6. data/CONTRIBUTORS +55 -0
  7. data/Gemfile +9 -0
  8. data/Guardfile +62 -0
  9. data/LICENSE +2 -2
  10. data/{README.md → README.markdown} +31 -37
  11. data/Rakefile +144 -0
  12. data/TODO +117 -0
  13. data/lib/pry.rb +146 -33
  14. data/lib/pry/cli.rb +13 -35
  15. data/lib/pry/code.rb +63 -24
  16. data/lib/pry/code/loc.rb +2 -2
  17. data/lib/pry/code_object.rb +21 -40
  18. data/lib/pry/command.rb +6 -9
  19. data/lib/pry/command_set.rb +37 -80
  20. data/lib/pry/commands.rb +1 -1
  21. data/lib/pry/commands/amend_line.rb +1 -1
  22. data/lib/pry/commands/bang.rb +1 -1
  23. data/lib/pry/commands/cat.rb +2 -11
  24. data/lib/pry/commands/cat/abstract_formatter.rb +1 -1
  25. data/lib/pry/commands/cat/exception_formatter.rb +7 -6
  26. data/lib/pry/commands/cat/file_formatter.rb +32 -15
  27. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  28. data/lib/pry/commands/cd.rb +3 -14
  29. data/lib/pry/commands/code_collector.rb +4 -4
  30. data/lib/pry/commands/easter_eggs.rb +3 -3
  31. data/lib/pry/commands/edit.rb +22 -10
  32. data/lib/pry/commands/edit/exception_patcher.rb +1 -1
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +2 -0
  34. data/lib/pry/{method/patcher.rb → commands/edit/method_patcher.rb} +37 -40
  35. data/lib/pry/commands/find_method.rb +22 -16
  36. data/lib/pry/commands/gem_install.rb +2 -5
  37. data/lib/pry/commands/gem_open.rb +1 -1
  38. data/lib/pry/commands/gist.rb +11 -10
  39. data/lib/pry/commands/help.rb +14 -14
  40. data/lib/pry/commands/hist.rb +5 -24
  41. data/lib/pry/commands/ls.rb +287 -56
  42. data/lib/pry/commands/play.rb +10 -44
  43. data/lib/pry/commands/pry_backtrace.rb +2 -1
  44. data/lib/pry/commands/raise_up.rb +1 -1
  45. data/lib/pry/commands/reload_code.rb +15 -31
  46. data/lib/pry/commands/ri.rb +3 -7
  47. data/lib/pry/commands/shell_command.rb +12 -17
  48. data/lib/pry/commands/shell_mode.rb +2 -2
  49. data/lib/pry/commands/show_doc.rb +0 -5
  50. data/lib/pry/commands/show_info.rb +10 -11
  51. data/lib/pry/commands/show_source.rb +3 -15
  52. data/lib/pry/commands/simple_prompt.rb +1 -1
  53. data/lib/pry/commands/toggle_color.rb +4 -8
  54. data/lib/pry/commands/whereami.rb +10 -18
  55. data/lib/pry/completion.rb +293 -0
  56. data/lib/pry/config.rb +233 -20
  57. data/lib/pry/core_extensions.rb +19 -29
  58. data/lib/pry/custom_completions.rb +6 -0
  59. data/lib/pry/editor.rb +103 -109
  60. data/lib/pry/helpers/base_helpers.rb +109 -22
  61. data/lib/pry/helpers/command_helpers.rb +8 -10
  62. data/lib/pry/helpers/documentation_helpers.rb +2 -1
  63. data/lib/pry/helpers/text.rb +5 -4
  64. data/lib/pry/history.rb +10 -21
  65. data/lib/pry/history_array.rb +0 -5
  66. data/lib/pry/hooks.rb +29 -9
  67. data/lib/pry/indent.rb +10 -5
  68. data/lib/pry/method.rb +86 -81
  69. data/lib/pry/method/weird_method_locator.rb +2 -4
  70. data/lib/pry/module_candidate.rb +14 -5
  71. data/lib/pry/pager.rb +48 -193
  72. data/lib/pry/plugins.rb +2 -2
  73. data/lib/pry/pry_class.rb +193 -104
  74. data/lib/pry/pry_instance.rb +154 -152
  75. data/lib/pry/rbx_method.rb +13 -0
  76. data/lib/pry/rbx_path.rb +1 -1
  77. data/lib/pry/repl.rb +14 -17
  78. data/lib/pry/repl_file_loader.rb +3 -8
  79. data/lib/pry/rubygem.rb +3 -3
  80. data/lib/pry/terminal.rb +3 -4
  81. data/lib/pry/test/helper.rb +11 -6
  82. data/lib/pry/version.rb +1 -1
  83. data/lib/pry/wrapped_module.rb +56 -49
  84. data/man/pry.1 +195 -0
  85. data/man/pry.1.html +204 -0
  86. data/man/pry.1.ronn +141 -0
  87. data/pry.gemspec +31 -0
  88. data/spec/Procfile +3 -0
  89. data/spec/cli_spec.rb +78 -0
  90. data/spec/code_object_spec.rb +277 -0
  91. data/spec/code_spec.rb +219 -0
  92. data/spec/command_helpers_spec.rb +29 -0
  93. data/spec/command_integration_spec.rb +562 -0
  94. data/spec/command_set_spec.rb +627 -0
  95. data/spec/command_spec.rb +821 -0
  96. data/spec/commands/amend_line_spec.rb +247 -0
  97. data/spec/commands/bang_spec.rb +18 -0
  98. data/spec/commands/cat_spec.rb +164 -0
  99. data/spec/commands/cd_spec.rb +250 -0
  100. data/spec/commands/disable_pry_spec.rb +25 -0
  101. data/spec/commands/edit_spec.rb +725 -0
  102. data/spec/commands/exit_all_spec.rb +27 -0
  103. data/spec/commands/exit_program_spec.rb +19 -0
  104. data/spec/commands/exit_spec.rb +28 -0
  105. data/spec/commands/find_method_spec.rb +70 -0
  106. data/spec/commands/gem_list_spec.rb +26 -0
  107. data/spec/commands/gist_spec.rb +79 -0
  108. data/spec/commands/help_spec.rb +56 -0
  109. data/spec/commands/hist_spec.rb +172 -0
  110. data/spec/commands/jump_to_spec.rb +15 -0
  111. data/spec/commands/ls_spec.rb +189 -0
  112. data/spec/commands/play_spec.rb +136 -0
  113. data/spec/commands/raise_up_spec.rb +56 -0
  114. data/spec/commands/save_file_spec.rb +177 -0
  115. data/spec/commands/show_doc_spec.rb +488 -0
  116. data/spec/commands/show_input_spec.rb +17 -0
  117. data/spec/commands/show_source_spec.rb +760 -0
  118. data/spec/commands/whereami_spec.rb +203 -0
  119. data/spec/completion_spec.rb +221 -0
  120. data/spec/control_d_handler_spec.rb +62 -0
  121. data/spec/documentation_helper_spec.rb +73 -0
  122. data/spec/editor_spec.rb +79 -0
  123. data/spec/exception_whitelist_spec.rb +21 -0
  124. data/spec/fixtures/candidate_helper1.rb +11 -0
  125. data/spec/fixtures/candidate_helper2.rb +8 -0
  126. data/spec/fixtures/example.erb +5 -0
  127. data/spec/fixtures/example_nesting.rb +33 -0
  128. data/spec/fixtures/show_source_doc_examples.rb +15 -0
  129. data/spec/fixtures/testlinkrc +2 -0
  130. data/spec/fixtures/testrc +2 -0
  131. data/spec/fixtures/testrcbad +2 -0
  132. data/spec/fixtures/whereami_helper.rb +6 -0
  133. data/spec/helper.rb +35 -0
  134. data/spec/helpers/bacon.rb +86 -0
  135. data/spec/helpers/mock_pry.rb +44 -0
  136. data/spec/helpers/repl_tester.rb +112 -0
  137. data/spec/helpers/table_spec.rb +105 -0
  138. data/spec/history_array_spec.rb +67 -0
  139. data/spec/hooks_spec.rb +522 -0
  140. data/spec/indent_spec.rb +301 -0
  141. data/spec/method_spec.rb +482 -0
  142. data/spec/prompt_spec.rb +61 -0
  143. data/spec/pry_defaults_spec.rb +420 -0
  144. data/spec/pry_history_spec.rb +69 -0
  145. data/spec/pry_output_spec.rb +95 -0
  146. data/spec/pry_repl_spec.rb +86 -0
  147. data/spec/pry_spec.rb +394 -0
  148. data/spec/pryrc_spec.rb +97 -0
  149. data/spec/run_command_spec.rb +25 -0
  150. data/spec/sticky_locals_spec.rb +147 -0
  151. data/spec/syntax_checking_spec.rb +81 -0
  152. data/spec/wrapped_module_spec.rb +261 -0
  153. data/wiki/Customizing-pry.md +397 -0
  154. data/wiki/Home.md +4 -0
  155. metadata +272 -61
  156. checksums.yaml +0 -7
  157. data/CHANGELOG.md +0 -714
  158. data/lib/pry/code/code_file.rb +0 -103
  159. data/lib/pry/color_printer.rb +0 -55
  160. data/lib/pry/commands/change_inspector.rb +0 -27
  161. data/lib/pry/commands/change_prompt.rb +0 -26
  162. data/lib/pry/commands/list_inspectors.rb +0 -35
  163. data/lib/pry/commands/list_prompts.rb +0 -35
  164. data/lib/pry/commands/ls/constants.rb +0 -47
  165. data/lib/pry/commands/ls/formatter.rb +0 -49
  166. data/lib/pry/commands/ls/globals.rb +0 -48
  167. data/lib/pry/commands/ls/grep.rb +0 -21
  168. data/lib/pry/commands/ls/instance_vars.rb +0 -39
  169. data/lib/pry/commands/ls/interrogatable.rb +0 -18
  170. data/lib/pry/commands/ls/jruby_hacks.rb +0 -49
  171. data/lib/pry/commands/ls/local_names.rb +0 -35
  172. data/lib/pry/commands/ls/local_vars.rb +0 -39
  173. data/lib/pry/commands/ls/ls_entity.rb +0 -70
  174. data/lib/pry/commands/ls/methods.rb +0 -57
  175. data/lib/pry/commands/ls/methods_helper.rb +0 -46
  176. data/lib/pry/commands/ls/self_methods.rb +0 -32
  177. data/lib/pry/commands/watch_expression.rb +0 -105
  178. data/lib/pry/commands/watch_expression/expression.rb +0 -38
  179. data/lib/pry/config/behavior.rb +0 -139
  180. data/lib/pry/config/convenience.rb +0 -25
  181. data/lib/pry/config/default.rb +0 -161
  182. data/lib/pry/exceptions.rb +0 -78
  183. data/lib/pry/input_completer.rb +0 -242
  184. data/lib/pry/input_lock.rb +0 -132
  185. data/lib/pry/inspector.rb +0 -27
  186. data/lib/pry/last_exception.rb +0 -61
  187. data/lib/pry/object_path.rb +0 -82
  188. data/lib/pry/output.rb +0 -50
  189. data/lib/pry/prompt.rb +0 -26
@@ -1,6 +1,6 @@
1
1
  # Default commands used by Pry.
2
2
  Pry::Commands = Pry::CommandSet.new
3
3
 
4
- Dir[File.expand_path('../commands', __FILE__) << '/*.rb'].each do |file|
4
+ Dir[File.expand_path('../commands', __FILE__) + '/*.rb'].each do |file|
5
5
  require file
6
6
  end
@@ -48,7 +48,7 @@ class Pry
48
48
 
49
49
  def insert_into_array(array, range)
50
50
  insert_slot = Array(range).first
51
- array.insert(insert_slot, arg_string[1..-1] << "\n")
51
+ array.insert(insert_slot, arg_string[1..-1] + "\n")
52
52
  end
53
53
 
54
54
  def replace_in_array(array, range)
@@ -1,6 +1,6 @@
1
1
  class Pry
2
2
  class Command::Bang < Pry::ClassCommand
3
- match(/^\s*!\s*$/)
3
+ match '!'
4
4
  group 'Editing'
5
5
  description 'Clear the input buffer.'
6
6
  command_options :use_prefix => false
@@ -41,20 +41,11 @@ class Pry
41
41
  FileFormatter.new(args.first, _pry_, opts).format
42
42
  end
43
43
 
44
- _pry_.pager.page output
44
+ stagger_output(output)
45
45
  end
46
46
 
47
47
  def complete(search)
48
- super | load_path_completions
49
- end
50
-
51
- def load_path_completions
52
- $LOAD_PATH.flat_map do |path|
53
- Dir[path + '/**/*'].map { |f|
54
- next if File.directory?(f)
55
- f.sub!(path + '/', '')
56
- }
57
- end
48
+ super + Bond::Rc.files(search.split(" ").last || '')
58
49
  end
59
50
  end
60
51
 
@@ -8,7 +8,7 @@ class Pry
8
8
  def decorate(content)
9
9
  content.code_type = code_type
10
10
  content.between(*between_lines).
11
- with_line_numbers(use_line_numbers?).highlighted
11
+ with_line_numbers(use_line_numbers?)
12
12
  end
13
13
 
14
14
  def code_type
@@ -1,9 +1,9 @@
1
1
  class Pry
2
2
  class Command::Cat
3
3
  class ExceptionFormatter < AbstractFormatter
4
- attr_reader :ex
5
- attr_reader :opts
6
- attr_reader :_pry_
4
+ attr_accessor :ex
5
+ attr_accessor :opts
6
+ attr_accessor :_pry_
7
7
 
8
8
  def initialize(exception, _pry_, opts)
9
9
  @ex = exception
@@ -16,14 +16,14 @@ class Pry
16
16
  set_file_and_dir_locals(backtrace_file, _pry_, _pry_.current_context)
17
17
  code = decorate(Pry::Code.from_file(backtrace_file).
18
18
  between(*start_and_end_line_for_code_window).
19
- with_marker(backtrace_line))
19
+ with_marker(backtrace_line)).to_s
20
20
  "#{header}#{code}"
21
21
  end
22
22
 
23
23
  private
24
24
 
25
25
  def code_window_size
26
- _pry_.config.default_window_size || 5
26
+ Pry.config.default_window_size || 5
27
27
  end
28
28
 
29
29
  def backtrace_level
@@ -44,7 +44,8 @@ class Pry
44
44
  end
45
45
 
46
46
  def backtrace_file
47
- Array(ex.bt_source_location_for(backtrace_level)).first
47
+ file = Array(ex.bt_source_location_for(backtrace_level)).first
48
+ (file && RbxPath.is_core_path?(file)) ? RbxPath.convert_path_to_full(file) : file
48
49
  end
49
50
 
50
51
  def backtrace_line
@@ -1,32 +1,31 @@
1
1
  class Pry
2
2
  class Command::Cat
3
3
  class FileFormatter < AbstractFormatter
4
- attr_reader :file_with_embedded_line
5
- attr_reader :opts
6
- attr_reader :_pry_
4
+ attr_accessor :file_with_embedded_line
5
+ attr_accessor :opts
6
+ attr_accessor :_pry_
7
7
 
8
8
  def initialize(file_with_embedded_line, _pry_, opts)
9
9
  @file_with_embedded_line = file_with_embedded_line
10
10
  @opts = opts
11
11
  @_pry_ = _pry_
12
- @code_from_file = Pry::Code.from_file(file_name)
13
12
  end
14
13
 
15
14
  def format
16
15
  raise CommandError, "Must provide a filename, --in, or --ex." if !file_with_embedded_line
17
16
 
18
17
  set_file_and_dir_locals(file_name, _pry_, _pry_.current_context)
19
- decorate(@code_from_file)
18
+ decorate(Pry::Code.from_file(file_name))
20
19
  end
21
20
 
21
+ private
22
+
22
23
  def file_and_line
23
- file_name, line_num = file_with_embedded_line.split(/:(?!\/|\\)/)
24
+ file_name, line_num = file_with_embedded_line.split(':')
24
25
 
25
- [file_name, line_num ? line_num.to_i : nil]
26
+ [File.expand_path(file_name), line_num ? line_num.to_i : nil]
26
27
  end
27
28
 
28
- private
29
-
30
29
  def file_name
31
30
  file_and_line.first
32
31
  end
@@ -36,7 +35,7 @@ class Pry
36
35
  end
37
36
 
38
37
  def code_window_size
39
- _pry_.config.default_window_size || 7
38
+ Pry.config.default_window_size || 7
40
39
  end
41
40
 
42
41
  def decorate(content)
@@ -48,18 +47,36 @@ class Pry
48
47
  end
49
48
 
50
49
  def detect_code_type_from_file(file_name)
51
- code_type = @code_from_file.code_type
50
+ name, ext = File.basename(file_name).split('.', 2)
52
51
 
53
- if code_type == :unknown
54
- name = File.basename(file_name).split('.', 2).first
52
+ if ext
53
+ case ext
54
+ when "py"
55
+ :python
56
+ when "rb", "gemspec", "rakefile", "ru", "pryrc", "irbrc"
57
+ :ruby
58
+ when "js"
59
+ return :javascript
60
+ when "yml", "prytheme"
61
+ :yaml
62
+ when "groovy"
63
+ :groovy
64
+ when "c"
65
+ :c
66
+ when "cpp"
67
+ :cpp
68
+ when "java"
69
+ :java
70
+ else
71
+ :text
72
+ end
73
+ else
55
74
  case name
56
75
  when "Rakefile", "Gemfile"
57
76
  :ruby
58
77
  else
59
78
  :text
60
79
  end
61
- else
62
- code_type
63
80
  end
64
81
  end
65
82
  end
@@ -20,7 +20,7 @@ class Pry
20
20
 
21
21
  content
22
22
  else
23
- decorate(Pry::Code(selected_input_items.first))
23
+ decorate(Pry::Code(selected_input_items.first)).to_s
24
24
  end
25
25
  end
26
26
 
@@ -9,7 +9,7 @@ class Pry
9
9
 
10
10
  Move into new context (object or scope). As in UNIX shells use `cd ..` to go
11
11
  back, `cd /` to return to Pry top-level and `cd -` to toggle between last two
12
- scopes. Complex syntax (e.g `cd ../@x/@y`) also supported.
12
+ scopes. Complex syntax (e.g `cd ../@x/y`) also supported.
13
13
 
14
14
  cd @x
15
15
  cd ..
@@ -21,19 +21,8 @@ class Pry
21
21
 
22
22
  def process
23
23
  state.old_stack ||= []
24
-
25
- if arg_string.strip == "-"
26
- unless state.old_stack.empty?
27
- _pry_.binding_stack, state.old_stack = state.old_stack, _pry_.binding_stack
28
- end
29
- else
30
- stack = ObjectPath.new(arg_string, _pry_.binding_stack).resolve
31
-
32
- if stack && stack != _pry_.binding_stack
33
- state.old_stack = _pry_.binding_stack
34
- _pry_.binding_stack = stack
35
- end
36
- end
24
+ stack, state.old_stack = context_from_object_path(arg_string, _pry_, state.old_stack)
25
+ _pry_.binding_stack = stack if stack
37
26
  end
38
27
  end
39
28
 
@@ -2,9 +2,9 @@ class Pry
2
2
  class Command::CodeCollector
3
3
  include Helpers::CommandHelpers
4
4
 
5
- attr_reader :args
6
- attr_reader :opts
7
- attr_reader :_pry_
5
+ attr_accessor :args
6
+ attr_accessor :opts
7
+ attr_accessor :_pry_
8
8
 
9
9
  # The name of the explicitly given file (if any).
10
10
  attr_accessor :file
@@ -91,7 +91,7 @@ class Pry
91
91
  # @return [String]
92
92
  def pry_output_content
93
93
  pry_array_content_as_string(_pry_.output_array, self.class.output_result_ranges) do |v|
94
- _pry_.config.gist.inspecter.call(v)
94
+ Pry.config.gist.inspecter.call(v)
95
95
  end
96
96
  end
97
97
 
@@ -83,8 +83,8 @@ TEXT
83
83
  end
84
84
 
85
85
  command "test-ansi", "" do
86
- prev_color = _pry_.config.color
87
- _pry_.config.color = true
86
+ prev_color = Pry.color
87
+ Pry.color = true
88
88
 
89
89
  picture = unindent <<-'EOS'.gsub(/[[:alpha:]!]/) { |s| text.red(s) }
90
90
  ____ _______________________
@@ -106,7 +106,7 @@ TEXT
106
106
  output.puts "\n" * 6
107
107
  output.puts "** ENV['TERM'] is #{ENV['TERM']} **\n\n"
108
108
 
109
- _pry_.config.color = prev_color
109
+ Pry.color = prev_color
110
110
  end
111
111
  end
112
112
  end
@@ -1,5 +1,6 @@
1
1
  class Pry
2
2
  class Command::Edit < Pry::ClassCommand
3
+ require 'pry/commands/edit/method_patcher'
3
4
  require 'pry/commands/edit/exception_patcher'
4
5
  require 'pry/commands/edit/file_and_line_locator'
5
6
 
@@ -12,7 +13,7 @@ class Pry
12
13
 
13
14
  Open a text editor. When no FILE is given, edits the pry input buffer.
14
15
  When a method/module/command is given, the code is opened in an editor.
15
- Ensure `Pry.config.editor` or `_pry_.config.editor` is set to your editor of choice.
16
+ Ensure `Pry.config.editor` is set to your editor of choice.
16
17
 
17
18
  edit sample.rb edit -p MyClass#my_method
18
19
  edit sample.rb --line 105 edit MyClass
@@ -30,7 +31,7 @@ class Pry
30
31
  opt.on :t, :temp, "Open an empty temporary file"
31
32
  opt.on :l, :line, "Jump to this line in the opened file",
32
33
  :argument => true, :as => Integer
33
- opt.on :n, :"no-reload", "Don't automatically reload the edited file"
34
+ opt.on :n, :"no-reload", "Don't automatically reload the edited code"
34
35
  opt.on :c, :current, "Open the current __FILE__ and at __LINE__ (as returned by `whereami`)"
35
36
  opt.on :r, :reload, "Reload the edited code immediately (default for ruby files)"
36
37
  opt.on :p, :patch, "Instead of editing the object's file, try to edit in a tempfile and apply as a monkey patch"
@@ -60,10 +61,12 @@ class Pry
60
61
  end
61
62
 
62
63
  def repl_edit
63
- content = Pry::Editor.new(_pry_).edit_tempfile_with_content(initial_temp_file_content,
64
+ content = Pry::Editor.edit_tempfile_with_content(initial_temp_file_content,
64
65
  initial_temp_file_content.lines.count)
65
- silence_warnings do
66
- eval_string.replace content
66
+ if repl_reload?
67
+ silence_warnings do
68
+ eval_string.replace content
69
+ end
67
70
  end
68
71
  end
69
72
 
@@ -80,7 +83,7 @@ class Pry
80
83
  ExceptionPatcher.new(_pry_, state, file_and_line_for_current_exception).perform_patch
81
84
  else
82
85
  if code_object.is_a?(Pry::Method)
83
- code_object.redefine Pry::Editor.new(_pry_).edit_tempfile_with_content(code_object.source)
86
+ MethodPatcher.new(_pry_, code_object).perform_patch
84
87
  else
85
88
  raise NotImplementedError, "Cannot yet patch #{code_object} objects!"
86
89
  end
@@ -116,12 +119,12 @@ class Pry
116
119
 
117
120
  ensure_file_name_is_valid(file_name)
118
121
 
119
- Pry::Editor.new(_pry_).invoke_editor(file_name, line, reload?(file_name))
122
+ Pry::Editor.invoke_editor(file_name, line, reload?(file_name))
120
123
  set_file_and_dir_locals(file_name)
121
124
 
122
125
  if reload?(file_name)
123
126
  silence_warnings do
124
- load file_name
127
+ TOPLEVEL_BINDING.eval(File.read(file_name), file_name)
125
128
  end
126
129
  end
127
130
  end
@@ -165,7 +168,12 @@ class Pry
165
168
  end
166
169
 
167
170
  def never_reload?
168
- opts.present?(:'no-reload') || _pry_.config.disable_auto_reload
171
+ opts.present?(:'no-reload') || Pry.config.disable_auto_reload
172
+ end
173
+
174
+ # conditions much less strict than for reload? (which is for file-based reloads)
175
+ def repl_reload?
176
+ !never_reload?
169
177
  end
170
178
 
171
179
  def reload?(file_name="")
@@ -186,9 +194,13 @@ class Pry
186
194
  end
187
195
 
188
196
  def probably_a_file?(str)
189
- [".rb", ".c", ".py", ".yml", ".gemspec"].include?(File.extname(str)) ||
197
+ [".rb", ".c", ".py", ".yml", ".gemspec"].include? File.extname(str) ||
190
198
  str =~ /\/|\\/
191
199
  end
200
+
201
+ def complete(search)
202
+ super + Bond::Rc.files(search.split(" ").last || '')
203
+ end
192
204
  end
193
205
 
194
206
  Pry::Commands.add_command(Pry::Command::Edit)
@@ -16,7 +16,7 @@ class Pry
16
16
  file_name, _ = file_and_line
17
17
  lines = state.dynamical_ex_file || File.read(file_name)
18
18
 
19
- source = Pry::Editor.new(_pry_).edit_tempfile_with_content(lines)
19
+ source = Pry::Editor.edit_tempfile_with_content(lines)
20
20
  _pry_.evaluate_ruby source
21
21
  state.dynamical_ex_file = source.split("\n")
22
22
  end
@@ -21,6 +21,8 @@ class Pry
21
21
  raise CommandError, "Exception has no associated file." if file_name.nil?
22
22
  raise CommandError, "Cannot edit exceptions raised in REPL." if Pry.eval_path == file_name
23
23
 
24
+ file_name = RbxPath.convert_path_to_full(file_name) if RbxPath.is_core_path?(file_name)
25
+
24
26
  [file_name, line]
25
27
  end
26
28
 
@@ -1,38 +1,37 @@
1
1
  class Pry
2
- class Method
3
- class Patcher
4
- attr_accessor :method
2
+ class Command::Edit
3
+ class MethodPatcher
4
+ attr_accessor :_pry_
5
+ attr_accessor :code_object
5
6
 
6
- @@source_cache = {}
7
-
8
- def initialize(method)
9
- @method = method
10
- end
11
-
12
- def self.code_for(filename)
13
- @@source_cache[filename]
7
+ def initialize(_pry_, code_object)
8
+ @_pry_ = _pry_
9
+ @code_object = code_object
14
10
  end
15
11
 
16
12
  # perform the patch
17
- def patch_in_ram(source)
18
- if method.alias?
13
+ def perform_patch
14
+ if code_object.alias?
19
15
  with_method_transaction do
20
- redefine source
16
+ _pry_.evaluate_ruby patched_code
21
17
  end
22
18
  else
23
- redefine source
19
+ _pry_.evaluate_ruby patched_code
24
20
  end
25
21
  end
26
22
 
27
23
  private
28
24
 
29
- def redefine(source)
30
- @@source_cache[cache_key] = source
31
- TOPLEVEL_BINDING.eval wrap(source), cache_key
25
+ def patched_code
26
+ @patched_code ||= wrap(Pry::Editor.edit_tempfile_with_content(adjusted_lines))
32
27
  end
33
28
 
34
- def cache_key
35
- "pry-redefined(0x#{method.owner.object_id.to_s(16)}##{method.name})"
29
+ # The method code adjusted so that the first line is rewritten
30
+ # so that def self.foo --> def foo
31
+ def adjusted_lines
32
+ lines = code_object.source.lines.to_a
33
+ lines[0] = definition_line_for_owner(lines.first)
34
+ lines
36
35
  end
37
36
 
38
37
  # Run some code ensuring that at the end target#meth_name will not have changed.
@@ -46,17 +45,17 @@ class Pry
46
45
  # @param [Module] target The owner of the method
47
46
 
48
47
  def with_method_transaction
49
- temp_name = "__pry_#{method.original_name}__"
50
- method = self.method
51
- method.owner.class_eval do
52
- alias_method temp_name, method.original_name
48
+ temp_name = "__pry_#{code_object.original_name}__"
49
+ co = code_object
50
+ code_object.owner.class_eval do
51
+ alias_method temp_name, co.original_name
53
52
  yield
54
- alias_method method.name, method.original_name
55
- alias_method method.original_name, temp_name
53
+ alias_method co.name, co.original_name
54
+ alias_method co.original_name, temp_name
56
55
  end
57
56
 
58
57
  ensure
59
- method.send(:remove_method, temp_name) rescue nil
58
+ co.send(:remove_method, temp_name) rescue nil
60
59
  end
61
60
 
62
61
  # Update the definition line so that it can be eval'd directly on the Method's
@@ -69,13 +68,13 @@ class Pry
69
68
  # This is necessarily done by String manipulation because we can't find out what
70
69
  # syntax is needed for the argument list by ruby-level introspection.
71
70
  #
72
- # @param [String] line The original definition line. e.g. def self.foo(bar, baz=1)
73
- # @return [String] The new definition line. e.g. def foo(bar, baz=1)
74
- def definition_for_owner(line)
75
- if line =~ /\Adef (?:.*?\.)?#{Regexp.escape(method.original_name)}(?=[\(\s;]|$)/
76
- "def #{method.original_name}#{$'}"
71
+ # @param String The original definition line. e.g. def self.foo(bar, baz=1)
72
+ # @return String The new definition line. e.g. def foo(bar, baz=1)
73
+ def definition_line_for_owner(line)
74
+ if line =~ /^def (?:.*?\.)?#{Regexp.escape(code_object.original_name)}(?=[\(\s;]|$)/
75
+ "def #{code_object.original_name}#{$'}"
77
76
  else
78
- raise CommandError, "Could not find original `def #{method.original_name}` line to patch."
77
+ raise CommandError, "Could not find original `def #{code_object.original_name}` line to patch."
79
78
  end
80
79
  end
81
80
 
@@ -88,17 +87,15 @@ class Pry
88
87
 
89
88
  # Update the source code so that when it has the right owner when eval'd.
90
89
  #
91
- # This (combined with definition_for_owner) is backup for the case that
90
+ # This (combined with definition_line_for_owner) is backup for the case that
92
91
  # wrap_for_nesting fails, to ensure that the method will stil be defined in
93
92
  # the correct place.
94
93
  #
95
94
  # @param [String] source The source to wrap
96
95
  # @return [String]
97
96
  def wrap_for_owner(source)
98
- Pry.current[:pry_owner] = method.owner
99
- owner_source = definition_for_owner(source)
100
- visibility_fix = "#{method.visibility.to_s} #{method.name.to_sym.inspect}"
101
- "Pry.current[:pry_owner].class_eval do; #{owner_source}\n#{visibility_fix}\nend"
97
+ Pry.current[:pry_owner] = code_object.owner
98
+ "Pry.current[:pry_owner].class_eval do\n#{source}\nend"
102
99
  end
103
100
 
104
101
  # Update the new source code to have the correct Module.nesting.
@@ -114,9 +111,9 @@ class Pry
114
111
  # @param [String] source The source to wrap.
115
112
  # @return [String]
116
113
  def wrap_for_nesting(source)
117
- nesting = Pry::Code.from_file(method.source_file).nesting_at(method.source_line)
114
+ nesting = Pry::Code.from_file(code_object.source_file).nesting_at(code_object.source_line)
118
115
 
119
- (nesting + [source] + nesting.map{ "end" } + [""]).join(";")
116
+ (nesting + [source] + nesting.map{ "end" } + [""]).join("\n")
120
117
  rescue Pry::Indent::UnparseableNestingError
121
118
  source
122
119
  end