pry 0.10.3 → 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 (159) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +439 -16
  3. data/LICENSE +1 -1
  4. data/README.md +362 -302
  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 +84 -97
  10. data/lib/pry/code/code_file.rb +37 -26
  11. data/lib/pry/code/code_range.rb +7 -5
  12. data/lib/pry/code/loc.rb +26 -13
  13. data/lib/pry/code.rb +42 -31
  14. data/lib/pry/code_object.rb +53 -28
  15. data/lib/pry/color_printer.rb +46 -35
  16. data/lib/pry/command.rb +197 -369
  17. data/lib/pry/command_set.rb +89 -114
  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 -72
  24. data/lib/pry/commands/cat/file_formatter.rb +56 -46
  25. data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
  26. data/lib/pry/commands/cat.rb +62 -54
  27. data/lib/pry/commands/cd.rb +40 -35
  28. data/lib/pry/commands/change_inspector.rb +29 -22
  29. data/lib/pry/commands/change_prompt.rb +48 -23
  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 +34 -23
  36. data/lib/pry/commands/edit.rb +185 -157
  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 -16
  40. data/lib/pry/commands/find_method.rb +168 -162
  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 +151 -149
  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 +35 -28
  47. data/lib/pry/commands/ls/constants.rb +59 -31
  48. data/lib/pry/commands/ls/formatter.rb +42 -36
  49. data/lib/pry/commands/ls/globals.rb +38 -36
  50. data/lib/pry/commands/ls/grep.rb +17 -15
  51. data/lib/pry/commands/ls/instance_vars.rb +29 -28
  52. data/lib/pry/commands/ls/interrogatable.rb +18 -12
  53. data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
  54. data/lib/pry/commands/ls/local_names.rb +26 -24
  55. data/lib/pry/commands/ls/local_vars.rb +38 -30
  56. data/lib/pry/commands/ls/ls_entity.rb +47 -52
  57. data/lib/pry/commands/ls/methods.rb +49 -51
  58. data/lib/pry/commands/ls/methods_helper.rb +46 -42
  59. data/lib/pry/commands/ls/self_methods.rb +23 -21
  60. data/lib/pry/commands/ls.rb +124 -103
  61. data/lib/pry/commands/nesting.rb +21 -17
  62. data/lib/pry/commands/play.rb +92 -82
  63. data/lib/pry/commands/pry_backtrace.rb +22 -17
  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 +60 -48
  67. data/lib/pry/commands/reset.rb +16 -12
  68. data/lib/pry/commands/ri.rb +57 -42
  69. data/lib/pry/commands/save_file.rb +45 -43
  70. data/lib/pry/commands/shell_command.rb +56 -29
  71. data/lib/pry/commands/shell_mode.rb +22 -18
  72. data/lib/pry/commands/show_doc.rb +80 -70
  73. data/lib/pry/commands/show_info.rb +194 -155
  74. data/lib/pry/commands/show_input.rb +16 -11
  75. data/lib/pry/commands/show_source.rb +110 -42
  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 +20 -16
  79. data/lib/pry/commands/watch_expression/expression.rb +32 -27
  80. data/lib/pry/commands/watch_expression.rb +89 -84
  81. data/lib/pry/commands/whereami.rb +156 -141
  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 +310 -20
  88. data/lib/pry/control_d_handler.rb +28 -0
  89. data/lib/pry/core_extensions.rb +22 -9
  90. data/lib/pry/editor.rb +56 -34
  91. data/lib/pry/env.rb +18 -0
  92. data/lib/pry/exception_handler.rb +43 -0
  93. data/lib/pry/exceptions.rb +13 -18
  94. data/lib/pry/forwardable.rb +27 -0
  95. data/lib/pry/helpers/base_helpers.rb +20 -62
  96. data/lib/pry/helpers/command_helpers.rb +52 -62
  97. data/lib/pry/helpers/documentation_helpers.rb +21 -12
  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 -85
  102. data/lib/pry/helpers.rb +3 -0
  103. data/lib/pry/history.rb +81 -55
  104. data/lib/pry/hooks.rb +60 -110
  105. data/lib/pry/indent.rb +74 -68
  106. data/lib/pry/input_completer.rb +199 -158
  107. data/lib/pry/input_lock.rb +7 -10
  108. data/lib/pry/inspector.rb +36 -24
  109. data/lib/pry/last_exception.rb +45 -45
  110. data/lib/pry/method/disowned.rb +19 -5
  111. data/lib/pry/method/patcher.rb +14 -8
  112. data/lib/pry/method/weird_method_locator.rb +79 -45
  113. data/lib/pry/method.rb +178 -124
  114. data/lib/pry/object_path.rb +37 -28
  115. data/lib/pry/output.rb +102 -16
  116. data/lib/pry/pager.rb +187 -174
  117. data/lib/pry/prompt.rb +213 -25
  118. data/lib/pry/pry_class.rb +119 -98
  119. data/lib/pry/pry_instance.rb +261 -224
  120. data/lib/pry/repl.rb +83 -29
  121. data/lib/pry/repl_file_loader.rb +27 -22
  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} +35 -32
  138. data/lib/pry/wrapped_module.rb +68 -63
  139. data/lib/pry.rb +133 -149
  140. metadata +58 -69
  141. data/lib/pry/commands/disabled_commands.rb +0 -2
  142. data/lib/pry/commands/gem_cd.rb +0 -26
  143. data/lib/pry/commands/gem_install.rb +0 -32
  144. data/lib/pry/commands/gem_list.rb +0 -33
  145. data/lib/pry/commands/gem_open.rb +0 -29
  146. data/lib/pry/commands/gist.rb +0 -101
  147. data/lib/pry/commands/install_command.rb +0 -53
  148. data/lib/pry/commands/list_prompts.rb +0 -35
  149. data/lib/pry/commands/simple_prompt.rb +0 -22
  150. data/lib/pry/commands.rb +0 -6
  151. data/lib/pry/config/behavior.rb +0 -139
  152. data/lib/pry/config/convenience.rb +0 -25
  153. data/lib/pry/config/default.rb +0 -161
  154. data/lib/pry/history_array.rb +0 -121
  155. data/lib/pry/plugins.rb +0 -103
  156. data/lib/pry/rbx_path.rb +0 -22
  157. data/lib/pry/rubygem.rb +0 -82
  158. data/lib/pry/terminal.rb +0 -79
  159. data/lib/pry/test/helper.rb +0 -170
@@ -1,26 +1,51 @@
1
- class Pry::Command::ChangePrompt < Pry::ClassCommand
2
- match 'change-prompt'
3
- group 'Input and Output'
4
- description 'Change the current prompt.'
5
- command_options argument_required: true
6
- banner <<-BANNER
7
- Usage: change-prompt NAME
8
-
9
- Change the current prompt. See list-prompts for a list of available
10
- prompts.
11
- BANNER
12
-
13
- def process(prompt)
14
- if prompt_map.key?(prompt)
15
- _pry_.prompt = prompt_map[prompt][:value]
16
- else
17
- raise Pry::CommandError, "'#{prompt}' isn't a known prompt!"
18
- end
19
- end
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Command
5
+ class ChangePrompt < Pry::ClassCommand
6
+ match 'change-prompt'
7
+ group 'Input and Output'
8
+ description 'Change the current prompt.'
9
+ command_options argument_required: true
10
+ banner <<-BANNER
11
+ Usage: change-prompt [OPTIONS] [NAME]
12
+
13
+ Change the current prompt.
14
+ BANNER
15
+
16
+ def options(opt)
17
+ opt.on(:l, :list, 'List the available prompts')
18
+ end
20
19
 
21
- private
22
- def prompt_map
23
- Pry::Prompt::MAP
20
+ def process(prompt)
21
+ if opts.present?(:l)
22
+ list_prompts
23
+ else
24
+ change_prompt(prompt)
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def list_prompts
31
+ prompts = Pry::Prompt.all.map do |name, prompt|
32
+ "#{bold(name)}#{red(' (selected)') if pry_instance.prompt == prompt}\n" +
33
+ prompt.description
34
+ end
35
+ output.puts(prompts.join("\n" * 2))
36
+ end
37
+
38
+ def change_prompt(prompt)
39
+ if Pry::Prompt[prompt]
40
+ pry_instance.prompt = Pry::Prompt[prompt]
41
+ else
42
+ raise Pry::CommandError,
43
+ "'#{prompt}' isn't a known prompt. Run `change-prompt --list` " \
44
+ "to see the list of known prompts."
45
+ end
46
+ end
47
+
48
+ Pry::Commands.add_command(self)
49
+ end
24
50
  end
25
- Pry::Commands.add_command(self)
26
51
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Command
5
+ class ClearScreen < Pry::ClassCommand
6
+ match 'clear-screen'
7
+ group 'Input and Output'
8
+ description 'Clear the contents of the screen/window Pry is running in.'
9
+
10
+ def process
11
+ if Pry::Helpers::Platform.windows?
12
+ pry_instance.config.system.call(pry_instance.output, 'cls', pry_instance)
13
+ else
14
+ pry_instance.config.system.call(pry_instance.output, 'clear', pry_instance)
15
+ end
16
+ end
17
+ Pry::Commands.add_command(self)
18
+ end
19
+ end
20
+ end
@@ -1,164 +1,181 @@
1
- class Pry
2
- class Command::CodeCollector
3
- include Helpers::CommandHelpers
4
-
5
- attr_reader :args
6
- attr_reader :opts
7
- attr_reader :_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_.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| 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_.config.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, _ = 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.new(_pry_).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