pry 0.10.3 → 0.14.2

Sign up to get free protection for your applications and to get access to all the features.
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
data/lib/pry/terminal.rb DELETED
@@ -1,79 +0,0 @@
1
- class Pry::Terminal
2
- class << self
3
- # Return a pair of [rows, columns] which gives the size of the window.
4
- #
5
- # If the window size cannot be determined, return nil.
6
- def screen_size
7
- rows, cols = actual_screen_size
8
- if rows.to_i != 0 && cols.to_i != 0
9
- [rows.to_i, cols.to_i]
10
- else
11
- nil
12
- end
13
- end
14
-
15
- # Return a screen size or a default if that fails.
16
- def size! default = [27, 80]
17
- screen_size || default
18
- end
19
-
20
- # Return a screen width or the default if that fails.
21
- def width!
22
- size![1]
23
- end
24
-
25
- # Return a screen height or the default if that fails.
26
- def height!
27
- size![0]
28
- end
29
-
30
- def actual_screen_size
31
- # The best way, if possible (requires non-jruby ≥1.9 or io-console gem)
32
- screen_size_according_to_io_console or
33
- # Fall back to the old standby, though it might be stale:
34
- screen_size_according_to_env or
35
- # Fall further back, though this one is also out of date without something
36
- # calling Readline.set_screen_size
37
- screen_size_according_to_readline or
38
- # Windows users can otherwise run ansicon and get a decent answer:
39
- screen_size_according_to_ansicon_env
40
- end
41
-
42
- def screen_size_according_to_io_console
43
- return if Pry::Helpers::BaseHelpers.jruby?
44
- require 'io/console'
45
- $stdout.winsize if $stdout.tty? and $stdout.respond_to?(:winsize)
46
- rescue LoadError
47
- # They probably don't have the io/console stdlib or the io-console gem.
48
- # We'll keep trying.
49
- end
50
-
51
- def screen_size_according_to_env
52
- size = [ENV['LINES'] || ENV['ROWS'], ENV['COLUMNS']]
53
- size if nonzero_column?(size)
54
- end
55
-
56
- def screen_size_according_to_readline
57
- if defined?(Readline) && Readline.respond_to?(:get_screen_size)
58
- size = Readline.get_screen_size
59
- size if nonzero_column?(size)
60
- end
61
- rescue Java::JavaLang::NullPointerException
62
- # This rescue won't happen on jrubies later than:
63
- # https://github.com/jruby/jruby/pull/436
64
- nil
65
- end
66
-
67
- def screen_size_according_to_ansicon_env
68
- return unless ENV['ANSICON'] =~ /\((.*)x(.*)\)/
69
- size = [$2, $1]
70
- size if nonzero_column?(size)
71
- end
72
-
73
- private
74
-
75
- def nonzero_column?(size)
76
- size[1].to_i > 0
77
- end
78
- end
79
- end
@@ -1,170 +0,0 @@
1
- require 'pry'
2
-
3
- # in case the tests call reset_defaults, ensure we reset them to
4
- # amended (test friendly) values
5
- class << Pry
6
- alias_method :orig_reset_defaults, :reset_defaults
7
- def reset_defaults
8
- orig_reset_defaults
9
-
10
- Pry.config.color = false
11
- Pry.config.pager = false
12
- Pry.config.should_load_rc = false
13
- Pry.config.should_load_local_rc= false
14
- Pry.config.should_load_plugins = false
15
- Pry.config.history.should_load = false
16
- Pry.config.history.should_save = false
17
- Pry.config.correct_indent = false
18
- Pry.config.hooks = Pry::Hooks.new
19
- Pry.config.collision_warning = false
20
- end
21
- end
22
- Pry.reset_defaults
23
-
24
- # A global space for storing temporary state during tests.
25
-
26
- module PryTestHelpers
27
-
28
- module_function
29
-
30
- # inject a variable into a binding
31
- def inject_var(name, value, b)
32
- Pry.current[:pry_local] = value
33
- b.eval("#{name} = ::Pry.current[:pry_local]")
34
- ensure
35
- Pry.current[:pry_local] = nil
36
- end
37
-
38
- def constant_scope(*names)
39
- names.each do |name|
40
- Object.remove_const name if Object.const_defined?(name)
41
- end
42
-
43
- yield
44
- ensure
45
- names.each do |name|
46
- Object.remove_const name if Object.const_defined?(name)
47
- end
48
- end
49
-
50
- # Open a temp file and yield it to the block, closing it after
51
- # @return [String] The path of the temp file
52
- def temp_file(ext='.rb')
53
- file = Tempfile.new(['pry', ext])
54
- yield file
55
- ensure
56
- file.close(true) if file
57
- File.unlink("#{file.path}c") if File.exists?("#{file.path}c") # rbx
58
- end
59
-
60
- def unindent(*args)
61
- Pry::Helpers::CommandHelpers.unindent(*args)
62
- end
63
-
64
- def mock_command(cmd, args=[], opts={})
65
- output = StringIO.new
66
- pry = Pry.new(output: output)
67
- ret = cmd.new(opts.merge(pry_instance: pry, :output => output)).call_safely(*args)
68
- Struct.new(:output, :return).new(output.string, ret)
69
- end
70
-
71
- def mock_exception(*mock_backtrace)
72
- StandardError.new.tap do |e|
73
- e.define_singleton_method(:backtrace) { mock_backtrace }
74
- end
75
- end
76
- end
77
-
78
- def pry_tester(*args, &block)
79
- if args.length == 0 || args[0].is_a?(Hash)
80
- args.unshift(Pry.toplevel_binding)
81
- end
82
-
83
- PryTester.new(*args).tap do |t|
84
- (class << t; self; end).class_eval(&block) if block
85
- end
86
- end
87
-
88
- def pry_eval(*eval_strs)
89
- if eval_strs.first.is_a? String
90
- binding = Pry.toplevel_binding
91
- else
92
- binding = Pry.binding_for(eval_strs.shift)
93
- end
94
-
95
- pry_tester(binding).eval(*eval_strs)
96
- end
97
-
98
- class PryTester
99
- extend Forwardable
100
-
101
- attr_reader :pry, :out
102
-
103
- def_delegators :@pry, :eval_string, :eval_string=
104
-
105
- def initialize(target = TOPLEVEL_BINDING, options = {})
106
- @pry = Pry.new(options.merge(:target => target))
107
- @history = options[:history]
108
-
109
- @pry.inject_sticky_locals!
110
- reset_output
111
- end
112
-
113
- def eval(*strs)
114
- reset_output
115
- result = nil
116
-
117
- strs.flatten.each do |str|
118
- str = "#{str.strip}\n"
119
- @history.push str if @history
120
-
121
- if @pry.process_command(str)
122
- result = last_command_result_or_output
123
- else
124
- result = @pry.evaluate_ruby(str)
125
- end
126
- end
127
-
128
- result
129
- end
130
-
131
- def push(*lines)
132
- Array(lines).flatten.each do |line|
133
- @pry.eval(line)
134
- end
135
- end
136
-
137
- def push_binding(context)
138
- @pry.push_binding context
139
- end
140
-
141
- def last_output
142
- @out.string if @out
143
- end
144
-
145
- def process_command(command_str)
146
- @pry.process_command(command_str) or raise "Not a valid command"
147
- last_command_result_or_output
148
- end
149
-
150
- def last_command_result
151
- result = Pry.current[:pry_cmd_result]
152
- result.retval if result
153
- end
154
-
155
- protected
156
-
157
- def last_command_result_or_output
158
- result = last_command_result
159
- if result != Pry::Command::VOID_VALUE
160
- result
161
- else
162
- last_output
163
- end
164
- end
165
-
166
- def reset_output
167
- @out = StringIO.new
168
- @pry.output = @out
169
- end
170
- end