pry 0.12.2-java → 0.13.0-java

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 (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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "pry/helpers/base_helpers"
2
4
  require "pry/helpers/options_helpers"
3
5
  require "pry/helpers/command_helpers"
@@ -1,200 +1,71 @@
1
- module Pry::Helpers; end
2
-
3
- # rubocop:disable Metrics/ModuleLength
4
- module Pry::Helpers::BaseHelpers
5
- extend self
6
-
7
- @mac_osx_warn = false
8
- # @deprecated Use {Pry::Helpers::Platform.mac_osx?} instead.
9
- def mac_osx?
10
- unless @mac_osx_warn
11
- loc = caller_locations(1..1).first
12
- warn(
13
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
14
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
15
- )
16
- @mac_osx_warn = true
17
- end
18
- Pry::Helpers::Platform.mac_osx?
19
- end
20
-
21
- @linux_warn = false
22
- # @deprecated Use {Pry::Helpers::Platform.mac_osx?} instead.
23
- def linux?
24
- unless @linux_warn
25
- loc = caller_locations(1..1).first
26
- warn(
27
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
28
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
29
- )
30
- @linux_warn = true
31
- end
32
- Pry::Helpers::Platform.linux?
33
- end
34
-
35
- @windows_warn = false
36
- # @deprecated Use {Pry::Helpers::Platform.windows?} instead.
37
- def windows?
38
- unless @windows_warn
39
- loc = caller_locations(1..1).first
40
- warn(
41
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
42
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
43
- )
44
- @windows_warn = true
45
- end
46
- Pry::Helpers::Platform.windows?
47
- end
48
-
49
- @windows_ansi_warn = false
50
- # @deprecated Use {Pry::Helpers::Platform.windows_ansi?} instead.
51
- def windows_ansi?
52
- unless @windows_ansi_warn
53
- loc = caller_locations(1..1).first
54
- warn(
55
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
56
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
57
- )
58
- @windows_ansi_warn = true
59
- end
60
- Pry::Helpers::Platform.windows_ansi?
61
- end
62
-
63
- @jruby_warn = false
64
- # @deprecated Use {Pry::Helpers::Platform.jruby?} instead.
65
- def jruby?
66
- unless @jruby_warn
67
- loc = caller_locations(1..1).first
68
- warn(
69
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
70
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
71
- )
72
- @jruby_warn = true
73
- end
74
- Pry::Helpers::Platform.jruby?
75
- end
76
-
77
- @jruby19_warn = false
78
- # @deprecated Use {Pry::Helpers::Platform.jruby_19?} instead.
79
- def jruby_19?
80
- unless @jruby19_warn
81
- loc = caller_locations(1..1).first
82
- warn(
83
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
84
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
85
- )
86
- @jruby19_warn = true
87
- end
88
- Pry::Helpers::Platform.jruby_19?
89
- end
90
-
91
- @mri_warn = false
92
- # @deprecated Use {Pry::Helpers::Platform.mri?} instead.
93
- def mri?
94
- unless @mri_warn
95
- loc = caller_locations(1..1).first
96
- warn(
97
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
98
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
99
- )
100
- @mri_warn = true
101
- end
102
- Pry::Helpers::Platform.mri?
103
- end
104
-
105
- @mri19_warn = false
106
- # @deprecated Use {Pry::Helpers::Platform.mri_19?} instead.
107
- def mri_19?
108
- unless @mri19_warn
109
- loc = caller_locations(1..1).first
110
- warn(
111
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
112
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
113
- )
114
- @mri19_warn = true
115
- end
116
- Pry::Helpers::Platform.mri_19?
117
- end
118
-
119
- @mri2_warn = false
120
- # @deprecated Use {Pry::Helpers::Platform.mri_2?} instead.
121
- def mri_2?
122
- unless @mri2_warn
123
- loc = caller_locations(1..1).first
124
- warn(
125
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
126
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
127
- )
128
- @mri2_warn = true
129
- end
130
- Pry::Helpers::Platform.mri_2?
131
- end
132
-
133
- def silence_warnings
134
- old_verbose = $VERBOSE
135
- $VERBOSE = nil
136
- begin
137
- yield
138
- ensure
139
- $VERBOSE = old_verbose
140
- end
141
- end
142
-
143
- # Acts like send but ignores any methods defined below Object or Class in the
144
- # inheritance hierarchy.
145
- # This is required to introspect methods on objects like Net::HTTP::Get that
146
- # have overridden the `method` method.
147
- def safe_send(obj, method, *args, &block)
148
- (Module === obj ? Module : Object).instance_method(method).bind(obj).call(*args, &block)
149
- end
150
- public :safe_send
151
-
152
- def find_command(name, set = Pry::Commands)
153
- command_match = set.find do |_, command|
154
- (listing = command.options[:listing]) == name && listing != nil
155
- end
156
- command_match.last if command_match
157
- end
158
-
159
- def not_a_real_file?(file)
160
- file =~ /^(\(.*\))$|^<.*>$/ || file =~ /__unknown__/ || file == "" || file == "-e"
161
- end
162
-
163
- def command_dependencies_met?(options)
164
- return true if !options[:requires_gem]
165
-
166
- Array(options[:requires_gem]).all? do |g|
167
- Pry::Rubygem.installed?(g)
168
- end
169
- end
170
-
171
- def use_ansi_codes?
172
- Pry::Helpers::Platform.windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
173
- end
174
-
175
- def colorize_code(code)
176
- CodeRay.scan(code, :ruby).term
177
- end
178
-
179
- def highlight(string, regexp, highlight_color = :bright_yellow)
180
- string.gsub(regexp) { |match| "<#{highlight_color}>#{match}</#{highlight_color}>" }
181
- end
182
-
183
- # formatting
184
- def heading(text)
185
- text = "#{text}\n--"
186
- "\e[1m#{text}\e[0m"
187
- end
188
-
189
- # Send the given text through the best available pager (if Pry.config.pager is
190
- # enabled). Infers where to send the output if used as a mixin.
191
- # DEPRECATED.
192
- def stagger_output(text, _out = nil)
193
- if defined?(_pry_) && _pry_
194
- _pry_.pager.page text
195
- else
196
- Pry.new.pager.page text
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ module Helpers
5
+ module BaseHelpers
6
+ extend self
7
+
8
+ def silence_warnings
9
+ old_verbose = $VERBOSE
10
+ $VERBOSE = nil
11
+ begin
12
+ yield
13
+ ensure
14
+ $VERBOSE = old_verbose
15
+ end
16
+ end
17
+
18
+ # Acts like send but ignores any methods defined below Object or Class in the
19
+ # inheritance hierarchy.
20
+ # This is required to introspect methods on objects like Net::HTTP::Get that
21
+ # have overridden the `method` method.
22
+ def safe_send(obj, method, *args, &block)
23
+ (obj.is_a?(Module) ? Module : Object).instance_method(method)
24
+ .bind(obj).call(*args, &block)
25
+ end
26
+
27
+ def find_command(name, set = Pry::Commands)
28
+ command_match = set.find do |_, command|
29
+ (listing = command.options[:listing]) == name && !listing.nil?
30
+ end
31
+ command_match.last if command_match
32
+ end
33
+
34
+ def not_a_real_file?(file)
35
+ file =~ /^(\(.*\))$|^<.*>$/ || file =~ /__unknown__/ || file == "" || file == "-e"
36
+ end
37
+
38
+ def use_ansi_codes?
39
+ Pry::Helpers::Platform.windows_ansi? ||
40
+ ((term = Pry::Env['TERM']) && term != "dumb")
41
+ end
42
+
43
+ def colorize_code(code)
44
+ SyntaxHighlighter.highlight(code)
45
+ end
46
+
47
+ def highlight(string, regexp, highlight_color = :bright_yellow)
48
+ string.gsub(regexp) do |match|
49
+ "<#{highlight_color}>#{match}</#{highlight_color}>"
50
+ end
51
+ end
52
+
53
+ # formatting
54
+ def heading(text)
55
+ text = "#{text}\n--"
56
+ "\e[1m#{text}\e[0m"
57
+ end
58
+
59
+ # Send the given text through the best available pager (if Pry.config.pager is
60
+ # enabled). Infers where to send the output if used as a mixin.
61
+ # DEPRECATED.
62
+ def stagger_output(text, _out = nil)
63
+ if defined?(pry_instance) && pry_instance
64
+ pry_instance.pager.page text
65
+ else
66
+ Pry.new.pager.page text
67
+ end
68
+ end
197
69
  end
198
70
  end
199
71
  end
200
- # rubocop:enable Metrics/ModuleLength
@@ -1,90 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tempfile'
4
+
1
5
  class Pry
2
6
  module Helpers
3
-
4
7
  module CommandHelpers
5
8
  include OptionsHelpers
6
9
 
7
- module_function
10
+ extend self
8
11
 
9
12
  # Open a temp file and yield it to the block, closing it after
10
13
  # @return [String] The path of the temp file
11
14
  def temp_file(ext = '.rb')
12
15
  file = Tempfile.new(['pry', ext])
13
- yield file
16
+ yield(file)
14
17
  ensure
15
- file.close(true) if file
18
+ file.close(true)
16
19
  end
17
20
 
18
- def internal_binding?(target)
19
- m = target.eval("::Kernel.__method__").to_s
21
+ def internal_binding?(context)
22
+ method_name = context.eval("::Kernel.__method__").to_s
20
23
  # class_eval is here because of http://jira.codehaus.org/browse/JRUBY-6753
21
- ["__binding__", "__pry__", "class_eval"].include?(m)
24
+ %w[__binding__ __pry__ class_eval].include?(method_name)
25
+ # TODO: codehaus is dead, there was no test for this and the
26
+ # description for the commit doesn't exist. Probably a candidate for
27
+ # removal so we have a chance to introduce a regression and document it
28
+ # properly.
22
29
  end
23
30
 
24
- def get_method_or_raise(name, target, opts = {}, omit_help = false)
25
- meth = Pry::Method.from_str(name, target, opts)
26
-
27
- if name && !meth
28
- command_error("The method '#{name}' could not be found.", omit_help, MethodNotFound)
31
+ def get_method_or_raise(method_name, context, opts = {})
32
+ method = Pry::Method.from_str(method_name, context, opts)
33
+ if !method && method_name
34
+ raise Pry::MethodNotFound, "method '#{method_name}' could not be found."
29
35
  end
30
36
 
31
37
  (opts[:super] || 0).times do
32
- if meth.super
33
- meth = meth.super
38
+ if method.super
39
+ method = method.super
34
40
  else
35
- command_error("'#{meth.name_with_owner}' has no super method.", omit_help, MethodNotFound)
41
+ raise Pry::MethodNotFound,
42
+ "'#{method.name_with_owner}' has no super method"
36
43
  end
37
44
  end
38
45
 
39
- if !meth || (!name && internal_binding?(target))
40
- command_error("No method name given, and context is not a method.", omit_help, MethodNotFound)
46
+ if !method || (!method_name && internal_binding?(context))
47
+ raise Pry::MethodNotFound,
48
+ 'no method name given, and context is not a method'
41
49
  end
42
50
 
43
- set_file_and_dir_locals(meth.source_file)
44
- meth
51
+ set_file_and_dir_locals(method.source_file)
52
+ method
45
53
  end
46
54
 
47
- def command_error(message, omit_help, klass = CommandError)
48
- message += " Type `#{command_name} --help` for help." unless omit_help
49
- raise klass, message
50
- end
51
-
52
- # Remove any common leading whitespace from every line in `text`.
53
- #
54
- # This can be used to make a HEREDOC line up with the left margin, without
55
+ # Remove any common leading whitespace from every line in `text`. This
56
+ # can be used to make a HEREDOC line up with the left margin, without
55
57
  # sacrificing the indentation level of the source code.
56
58
  #
57
- # e.g.
58
- # opt.banner unindent <<-USAGE
59
+ # @example
60
+ # opt.banner(unindent(<<-USAGE))
59
61
  # Lorem ipsum dolor sit amet, consectetur adipisicing elit,
60
62
  # sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
61
63
  # "Ut enim ad minim veniam."
62
64
  # USAGE
63
65
  #
64
- # Heavily based on textwrap.dedent from Python, which is:
65
- # Copyright (C) 1999-2001 Gregory P. Ward.
66
- # Copyright (C) 2002, 2003 Python Software Foundation.
67
- # Written by Greg Ward <gward@python.net>
68
- #
69
- # Licensed under <http://docs.python.org/license.html>
70
- # From <http://hg.python.org/cpython/file/6b9f0a6efaeb/Lib/textwrap.py>
71
- #
72
- # @param [String] text The text from which to remove indentation
73
- # @return [String] The text with indentation stripped.
74
- def unindent(text, left_padding = 0)
75
- # Empty blank lines
76
- text = text.sub(/^[ \t]+$/, '')
77
-
78
- # Find the longest common whitespace to all indented lines
79
- # Ignore lines containing just -- or ++ as these seem to be used by
80
- # comment authors as delimeters.
81
- margin = text.scan(/^[ \t]*(?!--\n|\+\+\n)(?=[^ \t\n])/).inject do |current_margin, next_indent|
66
+ # @param [String] dirty_text The text from which to remove indentation
67
+ # @return [String] the text with indentation stripped
68
+ def unindent(dirty_text, left_padding = 0)
69
+ text = dirty_text.sub(/\A[ \t]+\z/, '') # Empty blank lines.
70
+
71
+ # Find the longest common whitespace to all indented lines. Ignore lines
72
+ # containing just -- or ++ as these seem to be used by comment authors
73
+ # as delimeters.
74
+ scanned_text = text.scan(/^[ \t]*(?!--\n|\+\+\n)(?=[^ \t\n])/)
75
+ margin = scanned_text.inject do |current_margin, next_indent|
82
76
  if next_indent.start_with?(current_margin)
83
77
  current_margin
84
78
  elsif current_margin.start_with?(next_indent)
85
79
  next_indent
86
80
  else
87
- ""
81
+ ''
88
82
  end
89
83
  end
90
84
 
@@ -93,7 +87,7 @@ class Pry
93
87
 
94
88
  # Restrict a string to the given range of lines (1-indexed)
95
89
  # @param [String] content The string.
96
- # @param [Range, Fixnum] lines The line(s) to restrict it to.
90
+ # @param [Range, Integer] lines The line(s) to restrict it to.
97
91
  # @return [String] The resulting string.
98
92
  def restrict_to_lines(content, lines)
99
93
  line_range = one_index_range_or_number(lines)
@@ -101,11 +95,7 @@ class Pry
101
95
  end
102
96
 
103
97
  def one_index_number(line_number)
104
- if line_number > 0
105
- line_number - 1
106
- else
107
- line_number
108
- end
98
+ line_number > 0 ? line_number - 1 : line_number
109
99
  end
110
100
 
111
101
  # convert a 1-index range to a 0-indexed one
@@ -142,16 +132,15 @@ class Pry
142
132
  Range.new(a, b)
143
133
  end
144
134
 
145
- def set_file_and_dir_locals(file_name, _pry_ = _pry_(), target = target())
146
- return if !target or !file_name
135
+ def set_file_and_dir_locals(file_name, pry = pry_instance, ctx = target)
136
+ return if !ctx || !file_name
147
137
 
148
- _pry_.last_file = File.expand_path(file_name)
149
- _pry_.inject_local("_file_", _pry_.last_file, target)
138
+ pry.last_file = File.expand_path(file_name)
139
+ pry.inject_local("_file_", pry.last_file, ctx)
150
140
 
151
- _pry_.last_dir = File.dirname(_pry_.last_file)
152
- _pry_.inject_local("_dir_", _pry_.last_dir, target)
141
+ pry.last_dir = File.dirname(pry.last_file)
142
+ pry.inject_local("_dir_", pry.last_dir, ctx)
153
143
  end
154
144
  end
155
-
156
145
  end
157
146
  end