pry 0.12.2-java → 0.13.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +110 -1
  3. data/LICENSE +1 -1
  4. data/README.md +331 -269
  5. data/bin/pry +5 -0
  6. data/lib/pry.rb +133 -119
  7. data/lib/pry/basic_object.rb +8 -4
  8. data/lib/pry/block_command.rb +22 -0
  9. data/lib/pry/class_command.rb +194 -0
  10. data/lib/pry/cli.rb +40 -31
  11. data/lib/pry/code.rb +39 -27
  12. data/lib/pry/code/code_file.rb +28 -24
  13. data/lib/pry/code/code_range.rb +4 -2
  14. data/lib/pry/code/loc.rb +15 -8
  15. data/lib/pry/code_object.rb +40 -38
  16. data/lib/pry/color_printer.rb +47 -46
  17. data/lib/pry/command.rb +166 -369
  18. data/lib/pry/command_set.rb +76 -73
  19. data/lib/pry/command_state.rb +31 -0
  20. data/lib/pry/commands/amend_line.rb +86 -81
  21. data/lib/pry/commands/bang.rb +18 -14
  22. data/lib/pry/commands/bang_pry.rb +15 -11
  23. data/lib/pry/commands/cat.rb +61 -54
  24. data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
  25. data/lib/pry/commands/cat/exception_formatter.rb +71 -60
  26. data/lib/pry/commands/cat/file_formatter.rb +55 -49
  27. data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
  28. data/lib/pry/commands/cd.rb +40 -35
  29. data/lib/pry/commands/change_inspector.rb +29 -22
  30. data/lib/pry/commands/change_prompt.rb +44 -39
  31. data/lib/pry/commands/clear_screen.rb +16 -10
  32. data/lib/pry/commands/code_collector.rb +148 -133
  33. data/lib/pry/commands/disable_pry.rb +23 -19
  34. data/lib/pry/commands/easter_eggs.rb +19 -30
  35. data/lib/pry/commands/edit.rb +184 -161
  36. data/lib/pry/commands/edit/exception_patcher.rb +21 -17
  37. data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
  38. data/lib/pry/commands/exit.rb +39 -35
  39. data/lib/pry/commands/exit_all.rb +24 -20
  40. data/lib/pry/commands/exit_program.rb +20 -16
  41. data/lib/pry/commands/find_method.rb +168 -160
  42. data/lib/pry/commands/fix_indent.rb +16 -12
  43. data/lib/pry/commands/help.rb +140 -133
  44. data/lib/pry/commands/hist.rb +151 -150
  45. data/lib/pry/commands/import_set.rb +20 -16
  46. data/lib/pry/commands/jump_to.rb +25 -21
  47. data/lib/pry/commands/list_inspectors.rb +35 -28
  48. data/lib/pry/commands/ls.rb +124 -102
  49. data/lib/pry/commands/ls/constants.rb +59 -42
  50. data/lib/pry/commands/ls/formatter.rb +50 -46
  51. data/lib/pry/commands/ls/globals.rb +38 -34
  52. data/lib/pry/commands/ls/grep.rb +17 -13
  53. data/lib/pry/commands/ls/instance_vars.rb +29 -27
  54. data/lib/pry/commands/ls/interrogatable.rb +18 -12
  55. data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
  56. data/lib/pry/commands/ls/local_names.rb +26 -22
  57. data/lib/pry/commands/ls/local_vars.rb +38 -28
  58. data/lib/pry/commands/ls/ls_entity.rb +47 -51
  59. data/lib/pry/commands/ls/methods.rb +44 -43
  60. data/lib/pry/commands/ls/methods_helper.rb +46 -42
  61. data/lib/pry/commands/ls/self_methods.rb +23 -22
  62. data/lib/pry/commands/nesting.rb +21 -17
  63. data/lib/pry/commands/play.rb +93 -82
  64. data/lib/pry/commands/pry_backtrace.rb +24 -17
  65. data/lib/pry/commands/pry_version.rb +15 -11
  66. data/lib/pry/commands/raise_up.rb +27 -22
  67. data/lib/pry/commands/reload_code.rb +60 -48
  68. data/lib/pry/commands/reset.rb +16 -12
  69. data/lib/pry/commands/ri.rb +55 -45
  70. data/lib/pry/commands/save_file.rb +45 -43
  71. data/lib/pry/commands/shell_command.rb +51 -51
  72. data/lib/pry/commands/shell_mode.rb +21 -17
  73. data/lib/pry/commands/show_doc.rb +81 -68
  74. data/lib/pry/commands/show_info.rb +189 -171
  75. data/lib/pry/commands/show_input.rb +16 -11
  76. data/lib/pry/commands/show_source.rb +109 -45
  77. data/lib/pry/commands/stat.rb +35 -31
  78. data/lib/pry/commands/switch_to.rb +21 -15
  79. data/lib/pry/commands/toggle_color.rb +20 -16
  80. data/lib/pry/commands/watch_expression.rb +89 -86
  81. data/lib/pry/commands/watch_expression/expression.rb +32 -27
  82. data/lib/pry/commands/whereami.rb +156 -148
  83. data/lib/pry/commands/wtf.rb +75 -50
  84. data/lib/pry/config.rb +311 -25
  85. data/lib/pry/config/attributable.rb +22 -0
  86. data/lib/pry/config/lazy_value.rb +29 -0
  87. data/lib/pry/config/memoized_value.rb +34 -0
  88. data/lib/pry/config/value.rb +24 -0
  89. data/lib/pry/control_d_handler.rb +28 -0
  90. data/lib/pry/core_extensions.rb +9 -7
  91. data/lib/pry/editor.rb +48 -21
  92. data/lib/pry/env.rb +18 -0
  93. data/lib/pry/exception_handler.rb +43 -0
  94. data/lib/pry/exceptions.rb +13 -16
  95. data/lib/pry/forwardable.rb +5 -1
  96. data/lib/pry/helpers.rb +2 -0
  97. data/lib/pry/helpers/base_helpers.rb +68 -197
  98. data/lib/pry/helpers/command_helpers.rb +50 -61
  99. data/lib/pry/helpers/documentation_helpers.rb +20 -13
  100. data/lib/pry/helpers/options_helpers.rb +14 -7
  101. data/lib/pry/helpers/platform.rb +7 -5
  102. data/lib/pry/helpers/table.rb +33 -26
  103. data/lib/pry/helpers/text.rb +17 -14
  104. data/lib/pry/history.rb +48 -56
  105. data/lib/pry/hooks.rb +21 -12
  106. data/lib/pry/indent.rb +54 -50
  107. data/lib/pry/input_completer.rb +248 -230
  108. data/lib/pry/input_lock.rb +8 -9
  109. data/lib/pry/inspector.rb +36 -24
  110. data/lib/pry/last_exception.rb +45 -45
  111. data/lib/pry/method.rb +141 -94
  112. data/lib/pry/method/disowned.rb +16 -4
  113. data/lib/pry/method/patcher.rb +12 -3
  114. data/lib/pry/method/weird_method_locator.rb +68 -44
  115. data/lib/pry/object_path.rb +33 -25
  116. data/lib/pry/output.rb +121 -35
  117. data/lib/pry/pager.rb +41 -42
  118. data/lib/pry/plugins.rb +25 -8
  119. data/lib/pry/prompt.rb +123 -54
  120. data/lib/pry/pry_class.rb +61 -98
  121. data/lib/pry/pry_instance.rb +217 -215
  122. data/lib/pry/repl.rb +18 -22
  123. data/lib/pry/repl_file_loader.rb +27 -21
  124. data/lib/pry/ring.rb +11 -6
  125. data/lib/pry/slop.rb +574 -563
  126. data/lib/pry/slop/commands.rb +164 -169
  127. data/lib/pry/slop/option.rb +172 -168
  128. data/lib/pry/syntax_highlighter.rb +26 -0
  129. data/lib/pry/system_command_handler.rb +17 -0
  130. data/lib/pry/testable.rb +59 -61
  131. data/lib/pry/testable/evalable.rb +21 -12
  132. data/lib/pry/testable/mockable.rb +18 -10
  133. data/lib/pry/testable/pry_tester.rb +71 -56
  134. data/lib/pry/testable/utility.rb +29 -21
  135. data/lib/pry/testable/variables.rb +49 -43
  136. data/lib/pry/version.rb +3 -1
  137. data/lib/pry/warning.rb +27 -0
  138. data/lib/pry/wrapped_module.rb +51 -42
  139. data/lib/pry/wrapped_module/candidate.rb +21 -14
  140. metadata +31 -30
  141. data/lib/pry/commands.rb +0 -6
  142. data/lib/pry/commands/disabled_commands.rb +0 -2
  143. data/lib/pry/commands/gem_cd.rb +0 -26
  144. data/lib/pry/commands/gem_install.rb +0 -32
  145. data/lib/pry/commands/gem_list.rb +0 -33
  146. data/lib/pry/commands/gem_open.rb +0 -29
  147. data/lib/pry/commands/gem_readme.rb +0 -25
  148. data/lib/pry/commands/gem_search.rb +0 -40
  149. data/lib/pry/commands/gem_stats.rb +0 -83
  150. data/lib/pry/commands/gist.rb +0 -102
  151. data/lib/pry/commands/install_command.rb +0 -54
  152. data/lib/pry/config/behavior.rb +0 -255
  153. data/lib/pry/config/convenience.rb +0 -28
  154. data/lib/pry/config/default.rb +0 -159
  155. data/lib/pry/config/memoization.rb +0 -48
  156. data/lib/pry/platform.rb +0 -91
  157. data/lib/pry/rubygem.rb +0 -84
  158. data/lib/pry/terminal.rb +0 -91
@@ -1,27 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::DisablePry < Pry::ClassCommand
3
- match 'disable-pry'
4
- group 'Navigating Pry'
5
- description 'Stops all future calls to pry and exits the current session.'
4
+ class Command
5
+ class DisablePry < Pry::ClassCommand
6
+ match 'disable-pry'
7
+ group 'Navigating Pry'
8
+ description 'Stops all future calls to pry and exits the current session.'
6
9
 
7
- banner <<-'BANNER'
8
- Usage: disable-pry
10
+ banner <<-'BANNER'
11
+ Usage: disable-pry
9
12
 
10
- After this command is run any further calls to pry will immediately return `nil`
11
- without interrupting the flow of your program. This is particularly useful when
12
- you've debugged the problem you were having, and now wish the program to run to
13
- the end.
13
+ After this command is run any further calls to pry will immediately return `nil`
14
+ without interrupting the flow of your program. This is particularly useful when
15
+ you've debugged the problem you were having, and now wish the program to run to
16
+ the end.
14
17
 
15
- As alternatives, consider using `exit!` to force the current Ruby process
16
- to quit immediately; or using `edit-method -p` to remove the `binding.pry`
17
- from the code.
18
- BANNER
18
+ As alternatives, consider using `exit!` to force the current Ruby process
19
+ to quit immediately; or using `edit -p` to remove the `binding.pry`
20
+ from the code.
21
+ BANNER
19
22
 
20
- def process
21
- ENV['DISABLE_PRY'] = 'true'
22
- _pry_.run_command "exit"
23
+ def process
24
+ ENV['DISABLE_PRY'] = 'true'
25
+ pry_instance.run_command "exit"
26
+ end
23
27
  end
24
- end
25
28
 
26
- Pry::Commands.add_command(Pry::Command::DisablePry)
29
+ Pry::Commands.add_command(Pry::Command::DisablePry)
30
+ end
27
31
  end
@@ -1,26 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
4
  Pry::Commands.instance_eval do
3
- command "nyan-cat", "", requires_gem: ["nyancat"] do
4
- run ".nyancat"
5
- end
6
-
7
- command(/!s\/(.*?)\/(.*?)/, "") do |source, dest|
5
+ command(%r{!s/(.*?)/(.*?)}, "") do |source, dest|
8
6
  eval_string.gsub!(/#{source}/) { dest }
9
7
  run "show-input"
10
8
  end
11
9
 
12
- command "get-naked", "" do
13
- txt = %{
14
- --
15
- We dont have to take our clothes off to have a good time.
16
- We could dance & party all night And drink some cherry wine.
17
- -- Jermaine Stewart }
18
- output.puts txt
19
- txt
20
- end
21
-
22
10
  command "east-coker", "" do
23
- txt = %{
11
+ txt = %(
24
12
  --
25
13
  Now the light falls
26
14
  Across the open field, leaving the deep lane
@@ -33,13 +21,13 @@ class Pry
33
21
  The dahlias sleep in the empty silence.
34
22
  Wait for the early owl.
35
23
  -- T.S Eliot
36
- }
24
+ )
37
25
  output.puts txt
38
26
  txt
39
27
  end
40
28
 
41
29
  command "cohen-poem", "" do
42
- txt = %{
30
+ txt = %(
43
31
  --
44
32
  When this American woman,
45
33
  whose thighs are bound in casual red cloth,
@@ -56,7 +44,7 @@ class Pry
56
44
  that if you turn your head
57
45
  they are lost for hours.
58
46
  -- Leonard Cohen
59
- }
47
+ )
60
48
  output.puts txt
61
49
  txt
62
50
  end
@@ -79,34 +67,35 @@ class Pry
79
67
  O abstract hunger for things, impotent libido for moments,
80
68
  Intellectual orgy of feeling life!
81
69
  -- Fernando Pessoa
82
- TEXT
70
+ TEXT
83
71
  end
84
72
 
85
73
  command "test-ansi", "" do
86
- prev_color = _pry_.config.color
87
- _pry_.config.color = true
74
+ prev_color = pry_instance.config.color
75
+ pry_instance.config.color = true
88
76
 
89
- picture = unindent <<-'EOS'.gsub(/[[:alpha:]!]/) { |s| red(s) }
77
+ picture = unindent <<-'OUTPUT'.gsub(/[[:alpha:]!]/) { |s| red(s) }
90
78
  ____ _______________________
91
79
  / \ | A W G |
92
80
  / O O \ | N I O N ! |
93
81
  | | | S S R I ! |
94
82
  \ \__/ / __| I K ! |
95
83
  \____/ \________________________|
96
- EOS
84
+ OUTPUT
97
85
 
98
- if Helpers::Platform.windows_ansi?
99
- move_up = proc { |n| "\e[#{n}F" }
100
- else
101
- move_up = proc { |n| "\e[#{n}A\e[0G" }
102
- end
86
+ move_up =
87
+ if Helpers::Platform.windows_ansi?
88
+ proc { |n| "\e[#{n}F" }
89
+ else
90
+ proc { |n| "\e[#{n}A\e[0G" }
91
+ end
103
92
 
104
93
  output.puts "\n" * 6
105
94
  output.puts picture.lines.map(&:chomp).reverse.join(move_up[1])
106
95
  output.puts "\n" * 6
107
96
  output.puts "** ENV['TERM'] is #{ENV['TERM']} **\n\n"
108
97
 
109
- _pry_.config.color = prev_color
98
+ pry_instance.config.color = prev_color
110
99
  end
111
100
  end
112
101
  end
@@ -1,200 +1,223 @@
1
- class Pry
2
- class Command::Edit < Pry::ClassCommand
3
- require 'pry/commands/edit/exception_patcher'
4
- require 'pry/commands/edit/file_and_line_locator'
5
-
6
- match 'edit'
7
- group 'Editing'
8
- description 'Invoke the default editor on a file.'
9
-
10
- banner <<-'BANNER'
11
- Usage: edit [--no-reload|--reload|--patch] [--line LINE] [--temp|--ex|FILE[:LINE]|OBJECT|--in N]
12
-
13
- Open a text editor. When no FILE is given, edits the pry input buffer.
14
- 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
-
17
- edit sample.rb edit -p MyClass#my_method
18
- edit sample.rb --line 105 edit MyClass
19
- edit MyClass#my_method edit --ex
20
- edit --method edit --ex -p
21
-
22
- https://github.com/pry/pry/wiki/Editor-integration#wiki-Edit_command
23
- BANNER
24
-
25
- def options(opt)
26
- opt.on :e, :ex, "Open the file that raised the most recent exception (_ex_.file)",
27
- optional_argument: true, as: Integer
28
- opt.on :i, :in, "Open a temporary file containing the Nth input expression. N may be a range",
29
- optional_argument: true, as: Range, default: -1..-1
30
- opt.on :t, :temp, "Open an empty temporary file"
31
- opt.on :l, :line, "Jump to this line in the opened file",
32
- argument: true, as: Integer
33
- opt.on :n, :"no-reload", "Don't automatically reload the edited file"
34
- opt.on :c, :current, "Open the current __FILE__ and at __LINE__ (as returned by `whereami`)"
35
- opt.on :r, :reload, "Reload the edited code immediately (default for ruby files)"
36
- opt.on :p, :patch, "Instead of editing the object's file, try to edit in a tempfile and apply as a monkey patch"
37
- opt.on :m, :method, "Explicitly edit the _current_ method (when inside a method context)."
38
- end
1
+ # frozen_string_literal: true
39
2
 
40
- def process
41
- if bad_option_combination?
42
- raise CommandError, "Only one of --ex, --temp, --in, --method and FILE may be specified."
3
+ class Pry
4
+ class Command
5
+ class Edit < Pry::ClassCommand
6
+ match 'edit'
7
+ group 'Editing'
8
+ description 'Invoke the default editor on a file.'
9
+
10
+ banner <<-'BANNER'
11
+ Usage: edit [--no-reload|--reload|--patch] [--line LINE] [--temp|--ex|FILE[:LINE]|OBJECT|--in N]
12
+
13
+ Open a text editor. When no FILE is given, edits the pry input buffer.
14
+ When a method/module/command is given, the code is opened in an editor.
15
+ Ensure `Pry.config.editor` or `pry_instance.config.editor` is set to your editor of choice.
16
+
17
+ edit sample.rb edit -p MyClass#my_method
18
+ edit sample.rb --line 105 edit MyClass
19
+ edit MyClass#my_method edit --ex
20
+ edit --method edit --ex -p
21
+
22
+ https://github.com/pry/pry/wiki/Editor-integration#wiki-Edit_command
23
+ BANNER
24
+
25
+ def options(opt)
26
+ opt.on :e, :ex, "Open the file that raised the most recent exception " \
27
+ "(_ex_.file)",
28
+ optional_argument: true, as: Integer
29
+ opt.on :i, :in, "Open a temporary file containing the Nth input " \
30
+ "expression. N may be a range",
31
+ optional_argument: true, as: Range, default: -1..-1
32
+ opt.on :t, :temp, "Open an empty temporary file"
33
+ opt.on :l, :line, "Jump to this line in the opened file",
34
+ argument: true, as: Integer
35
+ opt.on :n, :"no-reload", "Don't automatically reload the edited file"
36
+ opt.on :c, :current, "Open the current __FILE__ and at __LINE__ (as " \
37
+ "returned by `whereami`)"
38
+ opt.on :r, :reload, "Reload the edited code immediately (default for " \
39
+ "ruby files)"
40
+ opt.on :p, :patch, "Instead of editing the object's file, try to edit " \
41
+ "in a tempfile and apply as a monkey patch"
42
+ opt.on :m, :method, "Explicitly edit the _current_ method (when " \
43
+ "inside a method context)."
43
44
  end
44
45
 
45
- if repl_edit?
46
- # code defined in pry, eval'd within pry.
47
- repl_edit
48
- elsif runtime_patch?
49
- # patch code without persisting changes, implies future changes are patches
50
- apply_runtime_patch
51
- else
52
- # code stored in actual files, eval'd at top-level
53
- file_edit
46
+ def process
47
+ if bad_option_combination?
48
+ raise CommandError, "Only one of --ex, --temp, --in, --method and " \
49
+ "FILE may be specified."
50
+ end
51
+
52
+ if repl_edit?
53
+ # code defined in pry, eval'd within pry.
54
+ repl_edit
55
+ elsif runtime_patch?
56
+ # patch code without persisting changes, implies future changes are patches
57
+ apply_runtime_patch
58
+ else
59
+ # code stored in actual files, eval'd at top-level
60
+ file_edit
61
+ end
54
62
  end
55
- end
56
63
 
57
- def repl_edit?
58
- !opts.present?(:ex) && !opts.present?(:current) && !opts.present?(:method) &&
59
- filename_argument.empty?
60
- end
64
+ def repl_edit?
65
+ !opts.present?(:ex) && !opts.present?(:current) && !opts.present?(:method) &&
66
+ filename_argument.empty?
67
+ end
61
68
 
62
- def repl_edit
63
- content = Pry::Editor.new(_pry_).edit_tempfile_with_content(initial_temp_file_content,
64
- initial_temp_file_content.lines.count)
65
- silence_warnings do
66
- eval_string.replace content
69
+ def repl_edit
70
+ content = Pry::Editor.new(pry_instance).edit_tempfile_with_content(
71
+ initial_temp_file_content,
72
+ initial_temp_file_content.lines.count
73
+ )
74
+ pry_instance.eval_string = content
75
+ Pry.history.push(content)
67
76
  end
68
- Pry.history.push(content)
69
- end
70
77
 
71
- def file_based_exception?
72
- opts.present?(:ex) && !opts.present?(:patch)
73
- end
78
+ def file_based_exception?
79
+ opts.present?(:ex) && !opts.present?(:patch)
80
+ end
74
81
 
75
- def runtime_patch?
76
- !file_based_exception? && (opts.present?(:patch) || previously_patched?(code_object) || pry_method?(code_object))
77
- end
82
+ def runtime_patch?
83
+ !file_based_exception? &&
84
+ (opts.present?(:patch) ||
85
+ previously_patched?(code_object) ||
86
+ pry_method?(code_object))
87
+ end
78
88
 
79
- def apply_runtime_patch
80
- if patch_exception?
81
- ExceptionPatcher.new(_pry_, state, file_and_line_for_current_exception).perform_patch
82
- else
83
- if code_object.is_a?(Pry::Method)
84
- code_object.redefine Pry::Editor.new(_pry_).edit_tempfile_with_content(code_object.source)
89
+ def apply_runtime_patch
90
+ if patch_exception?
91
+ ExceptionPatcher.new(
92
+ pry_instance, state, file_and_line_for_current_exception
93
+ ).perform_patch
94
+ elsif code_object.is_a?(Pry::Method)
95
+ code_object.redefine(
96
+ Pry::Editor.new(pry_instance).edit_tempfile_with_content(
97
+ code_object.source
98
+ )
99
+ )
85
100
  else
86
101
  raise NotImplementedError, "Cannot yet patch #{code_object} objects!"
87
102
  end
88
103
  end
89
- end
90
104
 
91
- def ensure_file_name_is_valid(file_name)
92
- raise CommandError, "Cannot find a valid file for #{filename_argument}" if !file_name
93
- raise CommandError, "#{file_name} is not a valid file name, cannot edit!" if not_a_real_file?(file_name)
94
- end
105
+ def ensure_file_name_is_valid(file_name)
106
+ unless file_name
107
+ raise CommandError, "Cannot find a valid file for #{filename_argument}"
108
+ end
95
109
 
96
- def file_and_line_for_current_exception
97
- FileAndLineLocator.from_exception(_pry_.last_exception, opts[:ex].to_i)
98
- end
110
+ return unless not_a_real_file?(file_name)
99
111
 
100
- def file_and_line
101
- file_name, line = if opts.present?(:current)
102
- FileAndLineLocator.from_binding(target)
103
- elsif opts.present?(:ex)
104
- file_and_line_for_current_exception
105
- elsif code_object
106
- FileAndLineLocator.from_code_object(code_object, filename_argument)
107
- else
108
- # when file and line are passed as a single arg, e.g my_file.rb:30
109
- FileAndLineLocator.from_filename_argument(filename_argument)
110
- end
111
-
112
- [file_name, opts.present?(:line) ? opts[:l].to_i : line]
113
- end
112
+ raise CommandError, "#{file_name} is not a valid file name, cannot edit!"
113
+ end
114
114
 
115
- def file_edit
116
- file_name, line = file_and_line
115
+ def file_and_line_for_current_exception
116
+ FileAndLineLocator.from_exception(pry_instance.last_exception, opts[:ex].to_i)
117
+ end
118
+
119
+ def file_and_line
120
+ file_name, line =
121
+ if opts.present?(:current)
122
+ FileAndLineLocator.from_binding(target)
123
+ elsif opts.present?(:ex)
124
+ file_and_line_for_current_exception
125
+ elsif code_object
126
+ FileAndLineLocator.from_code_object(code_object, filename_argument)
127
+ else
128
+ # when file and line are passed as a single arg, e.g my_file.rb:30
129
+ FileAndLineLocator.from_filename_argument(filename_argument)
130
+ end
131
+
132
+ [file_name, opts.present?(:line) ? opts[:l].to_i : line]
133
+ end
117
134
 
118
- ensure_file_name_is_valid(file_name)
135
+ def file_edit
136
+ file_name, line = file_and_line
119
137
 
120
- Pry::Editor.new(_pry_).invoke_editor(file_name, line, reload?(file_name))
121
- set_file_and_dir_locals(file_name)
138
+ ensure_file_name_is_valid(file_name)
122
139
 
123
- if reload?(file_name)
124
- silence_warnings do
125
- load file_name
126
- end
140
+ Pry::Editor.new(pry_instance).invoke_editor(file_name, line, reload?(file_name))
141
+ set_file_and_dir_locals(file_name)
142
+
143
+ return unless reload?(file_name)
144
+
145
+ silence_warnings { load(file_name) }
127
146
  end
128
- end
129
147
 
130
- def filename_argument
131
- args.join(' ')
132
- end
148
+ def filename_argument
149
+ args.join(' ')
150
+ end
133
151
 
134
- def code_object
135
- @code_object ||= !probably_a_file?(filename_argument) &&
136
- Pry::CodeObject.lookup(filename_argument, _pry_)
137
- end
152
+ def code_object
153
+ @code_object ||=
154
+ !probably_a_file?(filename_argument) &&
155
+ Pry::CodeObject.lookup(filename_argument, pry_instance)
156
+ end
138
157
 
139
- def pry_method?(code_object)
140
- code_object.is_a?(Pry::Method) &&
141
- code_object.pry_method?
142
- end
158
+ def pry_method?(code_object)
159
+ code_object.is_a?(Pry::Method) &&
160
+ code_object.pry_method?
161
+ end
143
162
 
144
- def previously_patched?(code_object)
145
- code_object.is_a?(Pry::Method) && Pry::Method::Patcher.code_for(code_object.source_location.first)
146
- end
163
+ def previously_patched?(code_object)
164
+ code_object.is_a?(Pry::Method) &&
165
+ Pry::Method::Patcher.code_for(code_object.source_location.first)
166
+ end
147
167
 
148
- def patch_exception?
149
- opts.present?(:ex) && opts.present?(:patch)
150
- end
168
+ def patch_exception?
169
+ opts.present?(:ex) && opts.present?(:patch)
170
+ end
151
171
 
152
- def bad_option_combination?
153
- [opts.present?(:ex), opts.present?(:temp),
154
- opts.present?(:in), opts.present?(:method), !filename_argument.empty?].count(true) > 1
155
- end
172
+ def bad_option_combination?
173
+ [
174
+ opts.present?(:ex), opts.present?(:temp),
175
+ opts.present?(:in), opts.present?(:method),
176
+ !filename_argument.empty?
177
+ ].count(true) > 1
178
+ end
156
179
 
157
- def input_expression
158
- case opts[:i]
159
- when Range
160
- (_pry_.input_ring[opts[:i]] || []).join
161
- when Integer
162
- _pry_.input_ring[opts[:i]] || ""
163
- else
164
- raise Pry::CommandError, "Not a valid range: #{opts[:i]}"
180
+ def input_expression
181
+ case opts[:i]
182
+ when Range
183
+ (pry_instance.input_ring[opts[:i]] || []).join
184
+ when Integer
185
+ pry_instance.input_ring[opts[:i]] || ""
186
+ else
187
+ raise Pry::CommandError, "Not a valid range: #{opts[:i]}"
188
+ end
165
189
  end
166
- end
167
190
 
168
- def reloadable?
169
- opts.present?(:reload) || opts.present?(:ex)
170
- end
191
+ def reloadable?
192
+ opts.present?(:reload) || opts.present?(:ex)
193
+ end
171
194
 
172
- def never_reload?
173
- opts.present?(:'no-reload') || _pry_.config.disable_auto_reload
174
- end
195
+ def never_reload?
196
+ opts.present?(:'no-reload') || pry_instance.config.disable_auto_reload
197
+ end
175
198
 
176
- def reload?(file_name = "")
177
- (reloadable? || file_name.end_with?(".rb")) && !never_reload?
178
- end
199
+ def reload?(file_name = "")
200
+ (reloadable? || file_name.end_with?(".rb")) && !never_reload?
201
+ end
179
202
 
180
- def initial_temp_file_content
181
- case
182
- when opts.present?(:temp)
183
- ""
184
- when opts.present?(:in)
185
- input_expression
186
- when eval_string.strip != ""
187
- eval_string
188
- else
189
- _pry_.input_ring.to_a.reverse_each.find { |x| x && x.strip != "" } || ""
203
+ def initial_temp_file_content
204
+ if opts.present?(:temp)
205
+ ""
206
+ elsif opts.present?(:in)
207
+ input_expression
208
+ elsif eval_string.strip != ""
209
+ eval_string
210
+ else
211
+ pry_instance.input_ring.to_a.reverse_each.find { |x| x && x.strip != "" } || ""
212
+ end
190
213
  end
191
- end
192
214
 
193
- def probably_a_file?(str)
194
- [".rb", ".c", ".py", ".yml", ".gemspec"].include?(File.extname(str)) ||
195
- str =~ /\/|\\/
215
+ def probably_a_file?(str)
216
+ [".rb", ".c", ".py", ".yml", ".gemspec"].include?(File.extname(str)) ||
217
+ str =~ %r{/|\\}
218
+ end
196
219
  end
197
- end
198
220
 
199
- Pry::Commands.add_command(Pry::Command::Edit)
221
+ Pry::Commands.add_command(Pry::Command::Edit)
222
+ end
200
223
  end