pry 0.9.12.2 → 0.14.2

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.
Files changed (237) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +1141 -0
  3. data/LICENSE +2 -2
  4. data/README.md +466 -0
  5. data/bin/pry +4 -7
  6. data/lib/pry/basic_object.rb +10 -0
  7. data/lib/pry/block_command.rb +22 -0
  8. data/lib/pry/class_command.rb +194 -0
  9. data/lib/pry/cli.rb +97 -92
  10. data/lib/pry/code/code_file.rb +114 -0
  11. data/lib/pry/code/code_range.rb +7 -4
  12. data/lib/pry/code/loc.rb +27 -14
  13. data/lib/pry/code.rb +62 -90
  14. data/lib/pry/code_object.rb +83 -39
  15. data/lib/pry/color_printer.rb +66 -0
  16. data/lib/pry/command.rb +202 -371
  17. data/lib/pry/command_set.rb +151 -133
  18. data/lib/pry/command_state.rb +31 -0
  19. data/lib/pry/commands/amend_line.rb +86 -82
  20. data/lib/pry/commands/bang.rb +18 -14
  21. data/lib/pry/commands/bang_pry.rb +15 -11
  22. data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
  23. data/lib/pry/commands/cat/exception_formatter.rb +85 -73
  24. data/lib/pry/commands/cat/file_formatter.rb +56 -63
  25. data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
  26. data/lib/pry/commands/cat.rb +64 -47
  27. data/lib/pry/commands/cd.rb +42 -26
  28. data/lib/pry/commands/change_inspector.rb +34 -0
  29. data/lib/pry/commands/change_prompt.rb +51 -0
  30. data/lib/pry/commands/clear_screen.rb +20 -0
  31. data/lib/pry/commands/code_collector.rb +148 -131
  32. data/lib/pry/commands/disable_pry.rb +23 -19
  33. data/lib/pry/commands/easter_eggs.rb +23 -34
  34. data/lib/pry/commands/edit/exception_patcher.rb +21 -17
  35. data/lib/pry/commands/edit/file_and_line_locator.rb +33 -24
  36. data/lib/pry/commands/edit.rb +183 -167
  37. data/lib/pry/commands/exit.rb +40 -35
  38. data/lib/pry/commands/exit_all.rb +24 -20
  39. data/lib/pry/commands/exit_program.rb +20 -17
  40. data/lib/pry/commands/find_method.rb +167 -167
  41. data/lib/pry/commands/fix_indent.rb +16 -12
  42. data/lib/pry/commands/help.rb +140 -133
  43. data/lib/pry/commands/hist.rb +153 -132
  44. data/lib/pry/commands/import_set.rb +20 -15
  45. data/lib/pry/commands/jump_to.rb +25 -21
  46. data/lib/pry/commands/list_inspectors.rb +42 -0
  47. data/lib/pry/commands/ls/constants.rb +75 -0
  48. data/lib/pry/commands/ls/formatter.rb +55 -0
  49. data/lib/pry/commands/ls/globals.rb +50 -0
  50. data/lib/pry/commands/ls/grep.rb +23 -0
  51. data/lib/pry/commands/ls/instance_vars.rb +40 -0
  52. data/lib/pry/commands/ls/interrogatable.rb +24 -0
  53. data/lib/pry/commands/ls/jruby_hacks.rb +55 -0
  54. data/lib/pry/commands/ls/local_names.rb +37 -0
  55. data/lib/pry/commands/ls/local_vars.rb +47 -0
  56. data/lib/pry/commands/ls/ls_entity.rb +65 -0
  57. data/lib/pry/commands/ls/methods.rb +55 -0
  58. data/lib/pry/commands/ls/methods_helper.rb +50 -0
  59. data/lib/pry/commands/ls/self_methods.rb +34 -0
  60. data/lib/pry/commands/ls.rb +100 -303
  61. data/lib/pry/commands/nesting.rb +21 -17
  62. data/lib/pry/commands/play.rb +93 -49
  63. data/lib/pry/commands/pry_backtrace.rb +22 -18
  64. data/lib/pry/commands/pry_version.rb +15 -11
  65. data/lib/pry/commands/raise_up.rb +33 -27
  66. data/lib/pry/commands/reload_code.rb +57 -48
  67. data/lib/pry/commands/reset.rb +16 -12
  68. data/lib/pry/commands/ri.rb +57 -38
  69. data/lib/pry/commands/save_file.rb +45 -43
  70. data/lib/pry/commands/shell_command.rb +66 -34
  71. data/lib/pry/commands/shell_mode.rb +22 -20
  72. data/lib/pry/commands/show_doc.rb +80 -65
  73. data/lib/pry/commands/show_info.rb +193 -159
  74. data/lib/pry/commands/show_input.rb +16 -11
  75. data/lib/pry/commands/show_source.rb +113 -33
  76. data/lib/pry/commands/stat.rb +35 -31
  77. data/lib/pry/commands/switch_to.rb +21 -15
  78. data/lib/pry/commands/toggle_color.rb +21 -13
  79. data/lib/pry/commands/watch_expression/expression.rb +43 -0
  80. data/lib/pry/commands/watch_expression.rb +110 -0
  81. data/lib/pry/commands/whereami.rb +157 -134
  82. data/lib/pry/commands/wtf.rb +78 -40
  83. data/lib/pry/config/attributable.rb +22 -0
  84. data/lib/pry/config/lazy_value.rb +29 -0
  85. data/lib/pry/config/memoized_value.rb +34 -0
  86. data/lib/pry/config/value.rb +24 -0
  87. data/lib/pry/config.rb +290 -220
  88. data/lib/pry/control_d_handler.rb +28 -0
  89. data/lib/pry/core_extensions.rb +50 -27
  90. data/lib/pry/editor.rb +130 -102
  91. data/lib/pry/env.rb +18 -0
  92. data/lib/pry/exception_handler.rb +43 -0
  93. data/lib/pry/exceptions.rb +73 -0
  94. data/lib/pry/forwardable.rb +27 -0
  95. data/lib/pry/helpers/base_helpers.rb +22 -151
  96. data/lib/pry/helpers/command_helpers.rb +55 -63
  97. data/lib/pry/helpers/documentation_helpers.rb +21 -13
  98. data/lib/pry/helpers/options_helpers.rb +15 -8
  99. data/lib/pry/helpers/platform.rb +55 -0
  100. data/lib/pry/helpers/table.rb +44 -32
  101. data/lib/pry/helpers/text.rb +96 -86
  102. data/lib/pry/helpers.rb +3 -0
  103. data/lib/pry/history.rb +101 -70
  104. data/lib/pry/hooks.rb +67 -137
  105. data/lib/pry/indent.rb +79 -73
  106. data/lib/pry/input_completer.rb +283 -0
  107. data/lib/pry/input_lock.rb +129 -0
  108. data/lib/pry/inspector.rb +39 -0
  109. data/lib/pry/last_exception.rb +61 -0
  110. data/lib/pry/method/disowned.rb +19 -5
  111. data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +51 -42
  112. data/lib/pry/method/weird_method_locator.rb +80 -44
  113. data/lib/pry/method.rb +225 -176
  114. data/lib/pry/object_path.rb +91 -0
  115. data/lib/pry/output.rb +136 -0
  116. data/lib/pry/pager.rb +227 -68
  117. data/lib/pry/prompt.rb +214 -0
  118. data/lib/pry/pry_class.rb +216 -289
  119. data/lib/pry/pry_instance.rb +438 -500
  120. data/lib/pry/repl.rb +256 -0
  121. data/lib/pry/repl_file_loader.rb +34 -35
  122. data/lib/pry/ring.rb +89 -0
  123. data/lib/pry/slop/LICENSE +20 -0
  124. data/lib/pry/slop/commands.rb +190 -0
  125. data/lib/pry/slop/option.rb +210 -0
  126. data/lib/pry/slop.rb +672 -0
  127. data/lib/pry/syntax_highlighter.rb +26 -0
  128. data/lib/pry/system_command_handler.rb +17 -0
  129. data/lib/pry/testable/evalable.rb +24 -0
  130. data/lib/pry/testable/mockable.rb +22 -0
  131. data/lib/pry/testable/pry_tester.rb +88 -0
  132. data/lib/pry/testable/utility.rb +34 -0
  133. data/lib/pry/testable/variables.rb +52 -0
  134. data/lib/pry/testable.rb +68 -0
  135. data/lib/pry/version.rb +3 -1
  136. data/lib/pry/warning.rb +20 -0
  137. data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +36 -43
  138. data/lib/pry/wrapped_module.rb +102 -103
  139. data/lib/pry.rb +135 -261
  140. metadata +94 -283
  141. data/.document +0 -2
  142. data/.gitignore +0 -16
  143. data/.travis.yml +0 -21
  144. data/.yardopts +0 -1
  145. data/CHANGELOG +0 -534
  146. data/CONTRIBUTORS +0 -55
  147. data/Gemfile +0 -9
  148. data/Guardfile +0 -62
  149. data/README.markdown +0 -400
  150. data/Rakefile +0 -140
  151. data/TODO +0 -117
  152. data/lib/pry/commands/disabled_commands.rb +0 -2
  153. data/lib/pry/commands/gem_cd.rb +0 -26
  154. data/lib/pry/commands/gem_install.rb +0 -29
  155. data/lib/pry/commands/gem_list.rb +0 -33
  156. data/lib/pry/commands/gem_open.rb +0 -29
  157. data/lib/pry/commands/gist.rb +0 -102
  158. data/lib/pry/commands/install_command.rb +0 -51
  159. data/lib/pry/commands/simple_prompt.rb +0 -22
  160. data/lib/pry/commands.rb +0 -6
  161. data/lib/pry/completion.rb +0 -304
  162. data/lib/pry/custom_completions.rb +0 -6
  163. data/lib/pry/history_array.rb +0 -116
  164. data/lib/pry/plugins.rb +0 -103
  165. data/lib/pry/rbx_method.rb +0 -13
  166. data/lib/pry/rbx_path.rb +0 -22
  167. data/lib/pry/rubygem.rb +0 -74
  168. data/lib/pry/terminal.rb +0 -78
  169. data/lib/pry/test/helper.rb +0 -185
  170. data/man/pry.1 +0 -195
  171. data/man/pry.1.html +0 -204
  172. data/man/pry.1.ronn +0 -141
  173. data/pry.gemspec +0 -30
  174. data/spec/Procfile +0 -3
  175. data/spec/cli_spec.rb +0 -78
  176. data/spec/code_object_spec.rb +0 -277
  177. data/spec/code_spec.rb +0 -219
  178. data/spec/command_helpers_spec.rb +0 -29
  179. data/spec/command_integration_spec.rb +0 -644
  180. data/spec/command_set_spec.rb +0 -627
  181. data/spec/command_spec.rb +0 -821
  182. data/spec/commands/amend_line_spec.rb +0 -247
  183. data/spec/commands/bang_spec.rb +0 -19
  184. data/spec/commands/cat_spec.rb +0 -164
  185. data/spec/commands/cd_spec.rb +0 -250
  186. data/spec/commands/disable_pry_spec.rb +0 -25
  187. data/spec/commands/edit_spec.rb +0 -727
  188. data/spec/commands/exit_all_spec.rb +0 -34
  189. data/spec/commands/exit_program_spec.rb +0 -19
  190. data/spec/commands/exit_spec.rb +0 -34
  191. data/spec/commands/find_method_spec.rb +0 -70
  192. data/spec/commands/gem_list_spec.rb +0 -26
  193. data/spec/commands/gist_spec.rb +0 -79
  194. data/spec/commands/help_spec.rb +0 -56
  195. data/spec/commands/hist_spec.rb +0 -181
  196. data/spec/commands/jump_to_spec.rb +0 -15
  197. data/spec/commands/ls_spec.rb +0 -181
  198. data/spec/commands/play_spec.rb +0 -140
  199. data/spec/commands/raise_up_spec.rb +0 -56
  200. data/spec/commands/save_file_spec.rb +0 -177
  201. data/spec/commands/show_doc_spec.rb +0 -510
  202. data/spec/commands/show_input_spec.rb +0 -17
  203. data/spec/commands/show_source_spec.rb +0 -782
  204. data/spec/commands/whereami_spec.rb +0 -203
  205. data/spec/completion_spec.rb +0 -239
  206. data/spec/control_d_handler_spec.rb +0 -58
  207. data/spec/documentation_helper_spec.rb +0 -73
  208. data/spec/editor_spec.rb +0 -79
  209. data/spec/exception_whitelist_spec.rb +0 -21
  210. data/spec/fixtures/candidate_helper1.rb +0 -11
  211. data/spec/fixtures/candidate_helper2.rb +0 -8
  212. data/spec/fixtures/example.erb +0 -5
  213. data/spec/fixtures/example_nesting.rb +0 -33
  214. data/spec/fixtures/show_source_doc_examples.rb +0 -15
  215. data/spec/fixtures/testrc +0 -2
  216. data/spec/fixtures/testrcbad +0 -2
  217. data/spec/fixtures/whereami_helper.rb +0 -6
  218. data/spec/helper.rb +0 -34
  219. data/spec/helpers/bacon.rb +0 -86
  220. data/spec/helpers/mock_pry.rb +0 -43
  221. data/spec/helpers/table_spec.rb +0 -105
  222. data/spec/history_array_spec.rb +0 -67
  223. data/spec/hooks_spec.rb +0 -522
  224. data/spec/indent_spec.rb +0 -301
  225. data/spec/input_stack_spec.rb +0 -90
  226. data/spec/method_spec.rb +0 -482
  227. data/spec/prompt_spec.rb +0 -60
  228. data/spec/pry_defaults_spec.rb +0 -419
  229. data/spec/pry_history_spec.rb +0 -99
  230. data/spec/pry_output_spec.rb +0 -95
  231. data/spec/pry_spec.rb +0 -504
  232. data/spec/run_command_spec.rb +0 -25
  233. data/spec/sticky_locals_spec.rb +0 -157
  234. data/spec/syntax_checking_spec.rb +0 -81
  235. data/spec/wrapped_module_spec.rb +0 -261
  236. data/wiki/Customizing-pry.md +0 -397
  237. data/wiki/Home.md +0 -4
@@ -1,164 +1,181 @@
1
- class Pry
2
- class Command::CodeCollector
3
- include Helpers::CommandHelpers
4
-
5
- attr_accessor :args
6
- attr_accessor :opts
7
- attr_accessor :_pry_
1
+ # frozen_string_literal: true
8
2
 
9
- # The name of the explicitly given file (if any).
10
- attr_accessor :file
3
+ class Pry
4
+ class Command
5
+ class CodeCollector
6
+ include Helpers::CommandHelpers
11
7
 
12
- class << self
13
- attr_accessor :input_expression_ranges
14
- attr_accessor :output_result_ranges
15
- end
8
+ attr_reader :args
9
+ attr_reader :opts
10
+ attr_reader :pry_instance
16
11
 
17
- @input_expression_ranges = []
18
- @output_result_ranges = []
12
+ # The name of the explicitly given file (if any).
13
+ attr_accessor :file
19
14
 
20
- def initialize(args, opts, _pry_)
21
- @args = args
22
- @opts = opts
23
- @_pry_ = _pry_
24
- end
15
+ class << self
16
+ attr_accessor :input_expression_ranges
17
+ attr_accessor :output_result_ranges
18
+ end
25
19
 
26
- # Add the `--lines`, `-o`, `-i`, `-s`, `-d` options.
27
- def self.inject_options(opt)
28
20
  @input_expression_ranges = []
29
21
  @output_result_ranges = []
30
22
 
31
- opt.on :l, :lines, "Restrict to a subset of lines. Takes a line number or range",
32
- :optional_argument => true, :as => Range, :default => 1..-1
33
- opt.on :o, :out, "Select lines from Pry's output result history. Takes an index or range",
34
- :optional_argument => true, :as => Range, :default => -5..-1 do |r|
35
- output_result_ranges << (r || (-5..-1))
23
+ def initialize(args, opts, pry_instance)
24
+ @args = args
25
+ @opts = opts
26
+ @pry_instance = pry_instance
36
27
  end
37
- opt.on :i, :in, "Select lines from Pry's input expression history. Takes an index or range",
38
- :optional_argument => true, :as => Range, :default => -5..-1 do |r|
39
- input_expression_ranges << (r || (-5..-1))
28
+
29
+ # Add the `--lines`, `-o`, `-i`, `-s`, `-d` options.
30
+ def self.inject_options(opt)
31
+ @input_expression_ranges = []
32
+ @output_result_ranges = []
33
+
34
+ opt.on :l, :lines, "Restrict to a subset of lines. Takes a line number " \
35
+ "or range",
36
+ optional_argument: true, as: Range, default: 1..-1
37
+ opt.on :o, :out, "Select lines from Pry's output result history. " \
38
+ "Takes an index or range",
39
+ optional_argument: true, as: Range, default: -5..-1 do |r|
40
+ output_result_ranges << (r || (-5..-1))
41
+ end
42
+ opt.on :i, :in, "Select lines from Pry's input expression history. " \
43
+ "Takes an index or range",
44
+ optional_argument: true, as: Range, default: -5..-1 do |r|
45
+ input_expression_ranges << (r || (-5..-1))
46
+ end
47
+ opt.on :s, :super, "Select the 'super' method. Can be repeated to " \
48
+ "traverse the ancestors",
49
+ as: :count
50
+ opt.on :d, :doc, "Select lines from the code object's documentation"
40
51
  end
41
- opt.on :s, :super, "Select the 'super' method. Can be repeated to traverse the ancestors",
42
- :as => :count
43
- opt.on :d, :doc, "Select lines from the code object's documentation"
44
- end
45
52
 
46
- # The content (i.e code/docs) for the selected object.
47
- # If the user provided a bare code object, it returns the source.
48
- # If the user provided the `-i` or `-o` switches, it returns the
49
- # selected input/output lines joined as a string. If the user used
50
- # `-d CODE_OBJECT` it returns the docs for that code object.
51
- #
52
- # @return [String]
53
- def content
54
- return @content if @content
55
- raise CommandError, "Only one of --out, --in, --doc and CODE_OBJECT may be specified." if bad_option_combination?
56
-
57
- content = case
58
- when opts.present?(:o)
59
- pry_output_content
60
- when opts.present?(:i)
61
- pry_input_content
62
- when opts.present?(:d)
63
- code_object_doc
64
- else
65
- code_object_source_or_file
66
- end
67
-
68
- @content ||= restrict_to_lines(content, line_range)
69
- end
53
+ # The content (i.e code/docs) for the selected object.
54
+ # If the user provided a bare code object, it returns the source.
55
+ # If the user provided the `-i` or `-o` switches, it returns the
56
+ # selected input/output lines joined as a string. If the user used
57
+ # `-d CODE_OBJECT` it returns the docs for that code object.
58
+ #
59
+ # @return [String]
60
+ def content
61
+ @content ||=
62
+ begin
63
+ if bad_option_combination?
64
+ raise CommandError,
65
+ "Only one of --out, --in, --doc and CODE_OBJECT may " \
66
+ "be specified."
67
+ end
68
+
69
+ content = if opts.present?(:o)
70
+ pry_output_content
71
+ elsif opts.present?(:i)
72
+ pry_input_content
73
+ elsif opts.present?(:d)
74
+ code_object_doc
75
+ else
76
+ code_object_source_or_file
77
+ end
78
+
79
+ restrict_to_lines(content, line_range)
80
+ end
81
+ end
70
82
 
71
- # The code object
72
- #
73
- # @return [Pry::WrappedModule, Pry::Method, Pry::Command]
74
- def code_object
75
- Pry::CodeObject.lookup(obj_name, _pry_, :super => opts[:super])
76
- end
83
+ # The code object
84
+ #
85
+ # @return [Pry::WrappedModule, Pry::Method, Pry::Command]
86
+ def code_object
87
+ Pry::CodeObject.lookup(obj_name, pry_instance, super: opts[:super])
88
+ end
77
89
 
78
- # Given a string and a range, return the `range` lines of that
79
- # string.
80
- #
81
- # @param [String] content
82
- # @param [Range, Fixnum] range
83
- # @return [String] The string restricted to the given range
84
- def restrict_to_lines(content, range)
85
- Array(content.lines.to_a[range]).join
86
- end
90
+ # Given a string and a range, return the `range` lines of that
91
+ # string.
92
+ #
93
+ # @param [String] content
94
+ # @param [Range, Fixnum] range
95
+ # @return [String] The string restricted to the given range
96
+ def restrict_to_lines(content, range)
97
+ Array(content.lines.to_a[range]).join
98
+ end
87
99
 
88
- # The selected `_pry_.output_array` as a string, as specified by
89
- # the `-o` switch.
90
- #
91
- # @return [String]
92
- def pry_output_content
93
- pry_array_content_as_string(_pry_.output_array, self.class.output_result_ranges) do |v|
94
- Pry.config.gist.inspecter.call(v)
100
+ # The selected `pry_instance.output_ring` as a string, as specified by
101
+ # the `-o` switch.
102
+ #
103
+ # @return [String]
104
+ def pry_output_content
105
+ pry_array_content_as_string(
106
+ pry_instance.output_ring,
107
+ self.class.output_result_ranges,
108
+ &:pretty_inspect
109
+ )
95
110
  end
96
- end
97
111
 
98
- # The selected `_pry_.input_array` as a string, as specified by
99
- # the `-i` switch.
100
- #
101
- # @return [String]
102
- def pry_input_content
103
- pry_array_content_as_string(_pry_.input_array, self.class.input_expression_ranges) { |v| v }
104
- end
112
+ # The selected `pry_instance.input_ring` as a string, as specified by
113
+ # the `-i` switch.
114
+ #
115
+ # @return [String]
116
+ def pry_input_content
117
+ pry_array_content_as_string(
118
+ pry_instance.input_ring, self.class.input_expression_ranges
119
+ ) { |v| v }
120
+ end
105
121
 
106
- # The line range passed to `--lines`, converted to a 0-indexed range.
107
- def line_range
108
- opts.present?(:lines) ? one_index_range_or_number(opts[:lines]) : 0..-1
109
- end
122
+ # The line range passed to `--lines`, converted to a 0-indexed range.
123
+ def line_range
124
+ opts.present?(:lines) ? one_index_range_or_number(opts[:lines]) : 0..-1
125
+ end
110
126
 
111
- # Name of the object argument
112
- def obj_name
113
- @obj_name ||= args.empty? ? "" : args.join(" ")
114
- end
127
+ # Name of the object argument
128
+ def obj_name
129
+ @obj_name ||= args.empty? ? "" : args.join(" ")
130
+ end
115
131
 
116
- private
132
+ private
117
133
 
118
- def bad_option_combination?
119
- [opts.present?(:in), opts.present?(:out),
120
- !args.empty?].count(true) > 1
121
- end
134
+ def bad_option_combination?
135
+ [opts.present?(:in), opts.present?(:out),
136
+ !args.empty?].count(true) > 1
137
+ end
138
+
139
+ def pry_array_content_as_string(array, ranges)
140
+ all = ''
141
+ ranges.each do |range|
142
+ if convert_to_range(range).first == 0
143
+ raise CommandError, "Minimum value for range is 1, not 0."
144
+ end
122
145
 
123
- def pry_array_content_as_string(array, ranges, &block)
124
- all = ''
125
- ranges.each do |range|
126
- raise CommandError, "Minimum value for range is 1, not 0." if convert_to_range(range).first == 0
146
+ ranged_array = Array(array[range]) || []
147
+ ranged_array.compact.each { |v| all += yield(v) }
148
+ end
127
149
 
128
- ranged_array = Array(array[range]) || []
129
- ranged_array.compact.each { |v| all << block.call(v) }
150
+ all
130
151
  end
131
152
 
132
- all
133
- end
153
+ def code_object_doc
154
+ (code_object && code_object.doc) || could_not_locate(obj_name)
155
+ end
134
156
 
135
- def code_object_doc
136
- (code_object && code_object.doc) or could_not_locate(obj_name)
137
- end
157
+ def code_object_source_or_file
158
+ (code_object && code_object.source) || file_content
159
+ end
138
160
 
139
- def code_object_source_or_file
140
- (code_object && code_object.source) || file_content
141
- end
161
+ def file_content
162
+ if File.exist?(obj_name)
163
+ # Set the file accessor.
164
+ self.file = obj_name
165
+ File.read(obj_name)
166
+ else
167
+ could_not_locate(obj_name)
168
+ end
169
+ end
142
170
 
143
- def file_content
144
- if File.exists?(obj_name)
145
- # Set the file accessor.
146
- self.file = obj_name
147
- File.read(obj_name)
148
- else
149
- could_not_locate(obj_name)
171
+ def could_not_locate(name)
172
+ raise CommandError, "Cannot locate: #{name}!"
150
173
  end
151
- end
152
174
 
153
- def could_not_locate(name)
154
- raise CommandError, "Cannot locate: #{name}!"
155
- end
175
+ def convert_to_range(range)
176
+ return range if range.is_a?(Range)
156
177
 
157
- def convert_to_range(n)
158
- if !n.is_a?(Range)
159
- (n..n)
160
- else
161
- n
178
+ (range..range)
162
179
  end
163
180
  end
164
181
  end
@@ -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
- text = %{
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 text
19
- text
20
- end
21
-
22
10
  command "east-coker", "" do
23
- text = %{
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
- }
37
- output.puts text
38
- text
24
+ )
25
+ output.puts txt
26
+ txt
39
27
  end
40
28
 
41
29
  command "cohen-poem", "" do
42
- text = %{
30
+ txt = %(
43
31
  --
44
32
  When this American woman,
45
33
  whose thighs are bound in casual red cloth,
@@ -56,9 +44,9 @@ class Pry
56
44
  that if you turn your head
57
45
  they are lost for hours.
58
46
  -- Leonard Cohen
59
- }
60
- output.puts text
61
- text
47
+ )
48
+ output.puts txt
49
+ txt
62
50
  end
63
51
 
64
52
  command "pessoa-poem", "" do
@@ -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.color
87
- Pry.color = true
74
+ prev_color = pry_instance.config.color
75
+ pry_instance.config.color = true
88
76
 
89
- picture = unindent <<-'EOS'.gsub(/[[:alpha:]!]/) { |s| text.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 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.color = prev_color
98
+ pry_instance.config.color = prev_color
110
99
  end
111
100
  end
112
101
  end
@@ -1,24 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::Edit
3
- class ExceptionPatcher
4
- attr_accessor :_pry_
5
- attr_accessor :state
6
- attr_accessor :file_and_line
4
+ class Command
5
+ class Edit
6
+ class ExceptionPatcher
7
+ attr_accessor :pry_instance
8
+ attr_accessor :state
9
+ attr_accessor :file_and_line
7
10
 
8
- def initialize(_pry_, state, exception_file_and_line)
9
- @_pry_ = _pry_
10
- @state = state
11
- @file_and_line = exception_file_and_line
12
- end
11
+ def initialize(pry_instance, state, exception_file_and_line)
12
+ @pry_instance = pry_instance
13
+ @state = state
14
+ @file_and_line = exception_file_and_line
15
+ end
13
16
 
14
- # perform the patch
15
- def perform_patch
16
- file_name, line = file_and_line
17
- lines = state.dynamical_ex_file || File.read(file_name)
17
+ # perform the patch
18
+ def perform_patch
19
+ file_name, = file_and_line
20
+ lines = state.dynamical_ex_file || File.read(file_name)
18
21
 
19
- source = Pry::Editor.edit_tempfile_with_content(lines)
20
- _pry_.evaluate_ruby source
21
- state.dynamical_ex_file = source.split("\n")
22
+ source = Pry::Editor.new(pry_instance).edit_tempfile_with_content(lines)
23
+ pry_instance.evaluate_ruby source
24
+ state.dynamical_ex_file = source.split("\n")
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -1,36 +1,45 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::Edit
3
- module FileAndLineLocator
4
- class << self
5
- def from_binding(target)
6
- [target.eval("__FILE__"), target.eval("__LINE__")]
7
- end
4
+ class Command
5
+ class Edit
6
+ module FileAndLineLocator
7
+ class << self
8
+ def from_binding(target)
9
+ if target.respond_to?(:source_location)
10
+ target.source_location
11
+ else
12
+ target.eval("[__FILE__, __LINE__]")
13
+ end
14
+ end
15
+
16
+ def from_code_object(code_object, filename_argument)
17
+ unless File.exist?(code_object.source_file.to_s)
18
+ raise CommandError, "Cannot find a file for #{filename_argument}!"
19
+ end
8
20
 
9
- def from_code_object(code_object, filename_argument)
10
- if File.exists?(code_object.source_file.to_s)
11
21
  [code_object.source_file, code_object.source_line]
12
- else
13
- raise CommandError, "Cannot find a file for #{filename_argument}!"
14
22
  end
15
- end
16
23
 
17
- def from_exception(exception, backtrace_level)
18
- raise CommandError, "No exception found." if exception.nil?
24
+ def from_exception(exception, backtrace_level)
25
+ raise CommandError, "No exception found." if exception.nil?
19
26
 
20
- file_name, line = exception.bt_source_location_for(backtrace_level)
21
- raise CommandError, "Exception has no associated file." if file_name.nil?
22
- raise CommandError, "Cannot edit exceptions raised in REPL." if Pry.eval_path == file_name
27
+ file_name, line = exception.bt_source_location_for(backtrace_level)
28
+ raise CommandError, "Exception has no associated file." if file_name.nil?
23
29
 
24
- file_name = RbxPath.convert_path_to_full(file_name) if RbxPath.is_core_path?(file_name)
30
+ if Pry.eval_path == file_name
31
+ raise CommandError, "Cannot edit exceptions raised in REPL."
32
+ end
25
33
 
26
- [file_name, line]
27
- end
34
+ [file_name, line]
35
+ end
28
36
 
29
- # when file and line are passed as a single arg, e.g my_file.rb:30
30
- def from_filename_argument(filename_argument)
31
- f = File.expand_path(filename_argument)
32
- l = f.sub!(/:(\d+)$/, "") ? $1.to_i : 1
33
- [f, l]
37
+ # when file and line are passed as a single arg, e.g my_file.rb:30
38
+ def from_filename_argument(filename_argument)
39
+ f = File.expand_path(filename_argument)
40
+ l = f.sub!(/:(\d+)$/, "") ? Regexp.last_match(1).to_i : 1
41
+ [f, l]
42
+ end
34
43
  end
35
44
  end
36
45
  end