pry 0.11.3 → 0.12.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 (118) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +157 -1
  3. data/LICENSE +1 -1
  4. data/README.md +13 -30
  5. data/bin/pry +0 -4
  6. data/lib/pry/cli.rb +17 -24
  7. data/lib/pry/code/code_file.rb +5 -4
  8. data/lib/pry/code/code_range.rb +3 -3
  9. data/lib/pry/code/loc.rb +14 -8
  10. data/lib/pry/code.rb +6 -6
  11. data/lib/pry/code_object.rb +4 -4
  12. data/lib/pry/color_printer.rb +1 -0
  13. data/lib/pry/command.rb +36 -29
  14. data/lib/pry/command_set.rb +17 -52
  15. data/lib/pry/commands/amend_line.rb +3 -4
  16. data/lib/pry/commands/bang.rb +1 -1
  17. data/lib/pry/commands/cat/exception_formatter.rb +9 -8
  18. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  19. data/lib/pry/commands/cat.rb +7 -6
  20. data/lib/pry/commands/change_prompt.rb +29 -9
  21. data/lib/pry/commands/clear_screen.rb +14 -0
  22. data/lib/pry/commands/code_collector.rb +9 -9
  23. data/lib/pry/commands/easter_eggs.rb +3 -3
  24. data/lib/pry/commands/edit.rb +8 -7
  25. data/lib/pry/commands/exit.rb +2 -1
  26. data/lib/pry/commands/find_method.rb +11 -13
  27. data/lib/pry/commands/gem_cd.rb +1 -1
  28. data/lib/pry/commands/gem_install.rb +2 -2
  29. data/lib/pry/commands/gem_list.rb +2 -2
  30. data/lib/pry/commands/gem_open.rb +1 -1
  31. data/lib/pry/commands/gem_search.rb +2 -2
  32. data/lib/pry/commands/gem_stats.rb +83 -0
  33. data/lib/pry/commands/gist.rb +7 -6
  34. data/lib/pry/commands/help.rb +3 -3
  35. data/lib/pry/commands/hist.rb +9 -8
  36. data/lib/pry/commands/import_set.rb +2 -1
  37. data/lib/pry/commands/install_command.rb +7 -6
  38. data/lib/pry/commands/list_inspectors.rb +2 -2
  39. data/lib/pry/commands/ls/constants.rb +4 -4
  40. data/lib/pry/commands/ls/formatter.rb +3 -2
  41. data/lib/pry/commands/ls/globals.rb +0 -2
  42. data/lib/pry/commands/ls/grep.rb +0 -2
  43. data/lib/pry/commands/ls/instance_vars.rb +0 -1
  44. data/lib/pry/commands/ls/local_names.rb +0 -2
  45. data/lib/pry/commands/ls/local_vars.rb +0 -2
  46. data/lib/pry/commands/ls/ls_entity.rb +0 -1
  47. data/lib/pry/commands/ls/methods.rb +0 -3
  48. data/lib/pry/commands/ls/methods_helper.rb +1 -1
  49. data/lib/pry/commands/ls/self_methods.rb +0 -1
  50. data/lib/pry/commands/ls.rb +27 -30
  51. data/lib/pry/commands/play.rb +1 -2
  52. data/lib/pry/commands/pry_backtrace.rb +1 -1
  53. data/lib/pry/commands/raise_up.rb +2 -1
  54. data/lib/pry/commands/ri.rb +5 -4
  55. data/lib/pry/commands/shell_command.rb +3 -2
  56. data/lib/pry/commands/shell_mode.rb +6 -6
  57. data/lib/pry/commands/show_doc.rb +5 -7
  58. data/lib/pry/commands/show_info.rb +25 -18
  59. data/lib/pry/commands/show_source.rb +5 -2
  60. data/lib/pry/commands/stat.rb +1 -1
  61. data/lib/pry/commands/watch_expression.rb +9 -7
  62. data/lib/pry/commands/whereami.rb +4 -4
  63. data/lib/pry/commands/wtf.rb +15 -2
  64. data/lib/pry/config/behavior.rb +229 -205
  65. data/lib/pry/config/convenience.rb +24 -21
  66. data/lib/pry/config/default.rb +153 -143
  67. data/lib/pry/config/memoization.rb +41 -37
  68. data/lib/pry/config.rb +33 -9
  69. data/lib/pry/core_extensions.rb +4 -3
  70. data/lib/pry/editor.rb +5 -12
  71. data/lib/pry/exceptions.rb +0 -2
  72. data/lib/pry/helpers/base_helpers.rb +133 -4
  73. data/lib/pry/helpers/command_helpers.rb +5 -4
  74. data/lib/pry/helpers/documentation_helpers.rb +2 -2
  75. data/lib/pry/helpers/options_helpers.rb +5 -5
  76. data/lib/pry/helpers/platform.rb +58 -0
  77. data/lib/pry/helpers/table.rb +20 -15
  78. data/lib/pry/helpers/text.rb +3 -4
  79. data/lib/pry/helpers.rb +1 -0
  80. data/lib/pry/history.rb +21 -8
  81. data/lib/pry/hooks.rb +3 -3
  82. data/lib/pry/indent.rb +15 -17
  83. data/lib/pry/input_completer.rb +12 -7
  84. data/lib/pry/input_lock.rb +0 -2
  85. data/lib/pry/last_exception.rb +1 -1
  86. data/lib/pry/method/disowned.rb +2 -1
  87. data/lib/pry/method/patcher.rb +2 -2
  88. data/lib/pry/method/weird_method_locator.rb +7 -8
  89. data/lib/pry/method.rb +37 -31
  90. data/lib/pry/object_path.rb +5 -4
  91. data/lib/pry/output.rb +3 -2
  92. data/lib/pry/pager.rb +194 -186
  93. data/lib/pry/platform.rb +79 -81
  94. data/lib/pry/plugins.rb +7 -3
  95. data/lib/pry/prompt.rb +144 -25
  96. data/lib/pry/pry_class.rb +53 -29
  97. data/lib/pry/pry_instance.rb +88 -55
  98. data/lib/pry/repl.rb +33 -4
  99. data/lib/pry/repl_file_loader.rb +1 -2
  100. data/lib/pry/ring.rb +84 -0
  101. data/lib/pry/rubygem.rb +6 -6
  102. data/lib/pry/slop/commands.rb +3 -4
  103. data/lib/pry/slop/option.rb +19 -21
  104. data/lib/pry/slop.rb +17 -17
  105. data/lib/pry/terminal.rb +2 -1
  106. data/lib/pry/testable/mockable.rb +2 -2
  107. data/lib/pry/testable/pry_tester.rb +1 -1
  108. data/lib/pry/testable/utility.rb +2 -2
  109. data/lib/pry/testable/variables.rb +1 -1
  110. data/lib/pry/version.rb +1 -1
  111. data/lib/pry/wrapped_module/candidate.rb +2 -2
  112. data/lib/pry/wrapped_module.rb +15 -15
  113. data/lib/pry.rb +17 -47
  114. metadata +8 -20
  115. data/lib/pry/commands/list_prompts.rb +0 -35
  116. data/lib/pry/commands/simple_prompt.rb +0 -22
  117. data/lib/pry/history_array.rb +0 -121
  118. data/lib/pry/rbx_path.rb +0 -22
@@ -1,149 +1,159 @@
1
- class Pry::Config::Default
2
- include Pry::Config::Behavior
3
- include Pry::Config::Memoization
1
+ class Pry
2
+ class Config < Pry::BasicObject
3
+ class Default
4
+ include Config::Behavior
5
+ include Config::Memoization
4
6
 
5
- def_memoized({
6
- input: proc {
7
- lazy_readline
8
- },
9
- output: proc {
10
- $stdout.tap { |out| out.sync = true }
11
- },
12
- commands: proc {
13
- Pry::Commands
14
- },
15
- prompt_name: proc {
16
- Pry::DEFAULT_PROMPT_NAME
17
- },
18
- prompt: proc {
19
- Pry::DEFAULT_PROMPT
20
- },
21
- prompt_safe_objects: proc {
22
- Pry::DEFAULT_PROMPT_SAFE_OBJECTS
23
- },
24
- print: proc {
25
- Pry::DEFAULT_PRINT
26
- },
27
- quiet: proc {
28
- false
29
- },
30
- exception_handler: proc {
31
- Pry::DEFAULT_EXCEPTION_HANDLER
32
- },
33
- exception_whitelist: proc {
34
- Pry::DEFAULT_EXCEPTION_WHITELIST
35
- },
36
- hooks: proc {
37
- Pry::DEFAULT_HOOKS
38
- },
39
- pager: proc {
40
- true
41
- },
42
- system: proc {
43
- Pry::DEFAULT_SYSTEM
44
- },
45
- color: proc {
46
- Pry::Helpers::BaseHelpers.use_ansi_codes?
47
- },
48
- default_window_size: proc {
49
- 5
50
- },
51
- editor: proc {
52
- Pry.default_editor_for_platform
53
- }, # TODO: Pry::Platform.editor
54
- should_load_rc: proc {
55
- true
56
- },
57
- should_load_local_rc: proc {
58
- true
59
- },
60
- should_trap_interrupts: proc {
61
- Pry::Platform.jruby?
62
- },
63
- disable_auto_reload: proc {
64
- false
65
- },
66
- command_prefix: proc {
67
- ""
68
- },
69
- auto_indent: proc {
70
- Pry::Helpers::BaseHelpers.use_ansi_codes?
71
- },
72
- correct_indent: proc {
73
- true
74
- },
75
- collision_warning: proc {
76
- false
77
- },
78
- output_prefix: proc {
79
- "=> "
80
- },
81
- requires: proc {
82
- []
83
- },
84
- should_load_requires: proc {
85
- true
86
- },
87
- should_load_plugins: proc {
88
- true
89
- },
90
- windows_console_warning: proc {
91
- true
92
- },
93
- control_d_handler: proc {
94
- Pry::DEFAULT_CONTROL_D_HANDLER
95
- },
96
- memory_size: proc {
97
- 100
98
- },
99
- extra_sticky_locals: proc {
100
- {}
101
- },
102
- command_completions: proc {
103
- proc { commands.keys }
104
- },
105
- file_completions: proc {
106
- proc { Dir["."] }
107
- },
108
- ls: proc {
109
- Pry::Config.from_hash(Pry::Command::Ls::DEFAULT_OPTIONS)
110
- },
111
- completer: proc {
112
- require "pry/input_completer"
113
- Pry::InputCompleter
114
- },
115
- gist: proc {
116
- Pry::Config.from_hash({inspecter: proc(&:pretty_inspect)}, nil)
117
- },
118
- history: proc {
119
- Pry::Config.from_hash({should_save: true, should_load: true}, nil).tap do |history|
120
- history.file = File.expand_path("~/.pry_history") rescue nil
121
- if history.file.nil?
122
- self.should_load_rc = false
123
- history.should_save = false
124
- history.should_load = false
125
- end
7
+ def_memoized({
8
+ input: proc {
9
+ lazy_readline
10
+ },
11
+ output: proc {
12
+ $stdout.tap { |out| out.sync = true }
13
+ },
14
+ commands: proc {
15
+ Pry::Commands
16
+ },
17
+ prompt_name: proc {
18
+ Pry::Prompt::DEFAULT_NAME
19
+ },
20
+ prompt: proc {
21
+ Pry::Prompt[:default][:value]
22
+ },
23
+ prompt_safe_contexts: proc {
24
+ Pry::Prompt::SAFE_CONTEXTS
25
+ },
26
+ print: proc {
27
+ Pry::DEFAULT_PRINT
28
+ },
29
+ quiet: proc {
30
+ false
31
+ },
32
+ exception_handler: proc {
33
+ Pry::DEFAULT_EXCEPTION_HANDLER
34
+ },
35
+ exception_whitelist: proc {
36
+ Pry::DEFAULT_EXCEPTION_WHITELIST
37
+ },
38
+ hooks: proc {
39
+ Pry::DEFAULT_HOOKS
40
+ },
41
+ pager: proc {
42
+ true
43
+ },
44
+ system: proc {
45
+ Pry::DEFAULT_SYSTEM
46
+ },
47
+ color: proc {
48
+ Pry::Helpers::BaseHelpers.use_ansi_codes?
49
+ },
50
+ default_window_size: proc {
51
+ 5
52
+ },
53
+ editor: proc {
54
+ Pry.default_editor_for_platform
55
+ },
56
+ should_load_rc: proc {
57
+ true
58
+ },
59
+ should_load_local_rc: proc {
60
+ true
61
+ },
62
+ should_trap_interrupts: proc {
63
+ Pry::Helpers::Platform.jruby?
64
+ },
65
+ disable_auto_reload: proc {
66
+ false
67
+ },
68
+ command_prefix: proc {
69
+ ""
70
+ },
71
+ auto_indent: proc {
72
+ Pry::Helpers::BaseHelpers.use_ansi_codes?
73
+ },
74
+ correct_indent: proc {
75
+ true
76
+ },
77
+ collision_warning: proc {
78
+ false
79
+ },
80
+ output_prefix: proc {
81
+ "=> "
82
+ },
83
+ requires: proc {
84
+ []
85
+ },
86
+ should_load_requires: proc {
87
+ true
88
+ },
89
+ should_load_plugins: proc {
90
+ true
91
+ },
92
+ windows_console_warning: proc {
93
+ true
94
+ },
95
+ control_d_handler: proc {
96
+ Pry::DEFAULT_CONTROL_D_HANDLER
97
+ },
98
+ memory_size: proc {
99
+ 100
100
+ },
101
+ extra_sticky_locals: proc {
102
+ {}
103
+ },
104
+ command_completions: proc {
105
+ proc { commands.keys }
106
+ },
107
+ file_completions: proc {
108
+ proc { Dir["."] }
109
+ },
110
+ ls: proc {
111
+ Pry::Config.from_hash(Pry::Command::Ls::DEFAULT_OPTIONS)
112
+ },
113
+ completer: proc {
114
+ require "pry/input_completer"
115
+ Pry::InputCompleter
116
+ },
117
+ gist: proc {
118
+ Pry::Config.from_hash({inspecter: proc(&:pretty_inspect)}, nil)
119
+ },
120
+ history: proc {
121
+ Pry::Config.from_hash({should_save: true, should_load: true}, nil).tap do |history|
122
+ history_file =
123
+ if File.exist?(File.expand_path('~/.pry_history'))
124
+ '~/.pry_history'
125
+ elsif ENV.key?('XDG_DATA_HOME') && ENV['XDG_DATA_HOME'] != ''
126
+ # See XDG Base Directory Specification at
127
+ # https://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
128
+ ENV['XDG_DATA_HOME'] + '/pry/pry_history'
129
+ else
130
+ '~/.local/share/pry/pry_history'
131
+ end
132
+ history.file = File.expand_path(history_file)
133
+ end
134
+ },
135
+ exec_string: proc {
136
+ ""
137
+ }
138
+ })
139
+
140
+ def initialize
141
+ super(nil)
126
142
  end
127
- },
128
- exec_string: proc {
129
- ""
130
- }
131
- })
132
143
 
133
- def initialize
134
- super(nil)
135
- end
144
+ private
136
145
 
137
- private
138
- def lazy_readline
139
- require 'readline'
140
- Readline
141
- rescue LoadError
142
- warn "Sorry, you can't use Pry without Readline or a compatible library."
143
- warn "Possible solutions:"
144
- warn " * Rebuild Ruby with Readline support using `--with-readline`"
145
- warn " * Use the rb-readline gem, which is a pure-Ruby port of Readline"
146
- warn " * Use the pry-coolline gem, a pure-ruby alternative to Readline"
147
- raise
146
+ def lazy_readline
147
+ require 'readline'
148
+ Readline
149
+ rescue LoadError
150
+ warn "Sorry, you can't use Pry without Readline or a compatible library."
151
+ warn "Possible solutions:"
152
+ warn " * Rebuild Ruby with Readline support using `--with-readline`"
153
+ warn " * Use the rb-readline gem, which is a pure-Ruby port of Readline"
154
+ warn " * Use the pry-coolline gem, a pure-ruby alternative to Readline"
155
+ raise
156
+ end
157
+ end
148
158
  end
149
159
  end
@@ -1,44 +1,48 @@
1
- module Pry::Config::Memoization
2
- MEMOIZED_METHODS = Hash.new {|h,k| h[k] = [] }
1
+ class Pry
2
+ class Config < Pry::BasicObject
3
+ module Memoization
4
+ MEMOIZED_METHODS = Hash.new { |h,k| h[k] = [] }
3
5
 
4
- module ClassMethods
5
- #
6
- # Defines one or more methods who return a constant value after being
7
- # called once.
8
- #
9
- # @example
10
- # class Foo
11
- # include Pry::Config::Memoization
12
- # def_memoized({
13
- # foo: proc {1+10},
14
- # bar: proc{"aaa"<<"a"}
15
- # })
16
- # end
17
- #
18
- # @param [{String => Proc}] method_table
19
- #
20
- # @return [void]
21
- #
22
- def def_memoized(method_table)
23
- method_table.each do |method_name, method|
24
- define_method(method_name) do
25
- method_table[method_name] = instance_eval(&method) if method_table[method_name].equal? method
26
- method_table[method_name]
6
+ module ClassMethods
7
+ #
8
+ # Defines one or more methods who return a constant value after being
9
+ # called once.
10
+ #
11
+ # @example
12
+ # class Foo
13
+ # include Pry::Config::Memoization
14
+ # def_memoized({
15
+ # foo: proc {1+10},
16
+ # bar: proc{"aaa"<<"a"}
17
+ # })
18
+ # end
19
+ #
20
+ # @param [{String => Proc}] method_table
21
+ #
22
+ # @return [void]
23
+ #
24
+ def def_memoized(method_table)
25
+ method_table.each do |method_name, method|
26
+ define_method(method_name) do
27
+ method_table[method_name] = instance_eval(&method) if method_table[method_name].equal? method
28
+ method_table[method_name]
29
+ end
30
+ end
31
+ MEMOIZED_METHODS[self] |= method_table.keys
27
32
  end
28
33
  end
29
- MEMOIZED_METHODS[self] |= method_table.keys
30
- end
31
- end
32
34
 
33
- def self.included(mod)
34
- mod.extend(ClassMethods)
35
- end
35
+ def self.included(mod)
36
+ mod.extend(ClassMethods)
37
+ end
36
38
 
37
- #
38
- # @return [Array<Symbol>]
39
- # Returns the names of methods that have been defined by {ClassMethods#def_memoized}.
40
- #
41
- def memoized_methods
42
- MEMOIZED_METHODS[self.class]
39
+ #
40
+ # @return [Array<Symbol>]
41
+ # Returns the names of methods that have been defined by {ClassMethods#def_memoized}.
42
+ #
43
+ def memoized_methods
44
+ MEMOIZED_METHODS[self.class]
45
+ end
46
+ end
43
47
  end
44
48
  end
data/lib/pry/config.rb CHANGED
@@ -1,11 +1,35 @@
1
- require_relative 'basic_object'
2
- class Pry::Config < Pry::BasicObject
3
- require_relative 'config/behavior'
4
- require_relative 'config/memoization'
5
- require_relative 'config/default'
6
- require_relative 'config/convenience'
7
- include Pry::Config::Behavior
8
- def self.shortcuts
9
- Convenience::SHORTCUTS
1
+ class Pry
2
+ # The Pry config.
3
+ # @api public
4
+ class Config < Pry::BasicObject
5
+ # Wraps a block so it can have a name.
6
+ #
7
+ # @example
8
+ # proc1 = proc {}
9
+ # proc2 = Pry::Config::Lazy.new(&proc {})
10
+ #
11
+ # proc1.is_a?(Pry::Config::Lazy)
12
+ # #=> false
13
+ # proc2.is_a?(Pry::Config::Lazy)
14
+ # #=> true
15
+ #
16
+ # @api private
17
+ # @since v0.12.0
18
+ class Lazy
19
+ def initialize(&block)
20
+ @block = block
21
+ end
22
+
23
+ # @return [Object]
24
+ def call
25
+ @block.call
26
+ end
27
+ end
28
+
29
+ include Behavior
30
+
31
+ def self.shortcuts
32
+ Convenience::SHORTCUTS
33
+ end
10
34
  end
11
35
  end
@@ -38,7 +38,7 @@ class Object
38
38
  # end
39
39
  # my_method()
40
40
  # @see Pry.start
41
- def pry(object=nil, hash={})
41
+ def pry(object = nil, hash = {})
42
42
  if object.nil? || Hash === object
43
43
  Pry.start(self, object || {})
44
44
  else
@@ -81,12 +81,13 @@ class Object
81
81
  # This fixes the following two spec failures, at https://travis-ci.org/pry/pry/jobs/274470002
82
82
  # 1) ./spec/pry_spec.rb:360:in `block in (root)'
83
83
  # 2) ./spec/pry_spec.rb:366:in `block in (root)'
84
- return class_eval {binding} if Pry::Helpers::BaseHelpers.jruby? and self.name == nil
84
+ return class_eval { binding } if Pry::Helpers::Platform.jruby? and self.name == nil
85
+
85
86
  # class_eval sets both self and the default definee to this class.
86
87
  return class_eval("binding")
87
88
  end
88
89
 
89
- unless respond_to?(:__pry__)
90
+ unless self.class.method_defined?(:__pry__)
90
91
  # The easiest way to check whether an object has a working singleton class
91
92
  # is to try and define a method on it. (just checking for the presence of
92
93
  # the singleton class gives false positives for `true` and `false`).
data/lib/pry/editor.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  class Pry
2
2
  class Editor
3
- include Pry::Helpers::BaseHelpers
4
3
  include Pry::Helpers::CommandHelpers
5
4
 
6
5
  attr_reader :_pry_
@@ -9,7 +8,7 @@ class Pry
9
8
  @_pry_ = _pry_
10
9
  end
11
10
 
12
- def edit_tempfile_with_content(initial_content, line=1)
11
+ def edit_tempfile_with_content(initial_content, line = 1)
13
12
  temp_file do |f|
14
13
  f.puts(initial_content)
15
14
  f.flush
@@ -19,13 +18,13 @@ class Pry
19
18
  end
20
19
  end
21
20
 
22
- def invoke_editor(file, line, blocking=true)
21
+ def invoke_editor(file, line, blocking = true)
23
22
  raise CommandError, "Please set Pry.config.editor or export $VISUAL or $EDITOR" unless _pry_.config.editor
24
23
 
25
24
  editor_invocation = build_editor_invocation_string(file, line, blocking)
26
25
  return nil unless editor_invocation
27
26
 
28
- if jruby?
27
+ if Helpers::Platform.jruby?
29
28
  open_editor_on_jruby(editor_invocation)
30
29
  else
31
30
  open_editor(editor_invocation)
@@ -43,12 +42,7 @@ class Pry
43
42
  args = [file, line, blocking][0...(_pry_.config.editor.arity)]
44
43
  _pry_.config.editor.call(*args)
45
44
  else
46
- sanitized_file = if windows?
47
- file
48
- else
49
- Shellwords.escape(file)
50
- end
51
-
45
+ sanitized_file = Helpers::Platform.windows? ? file : Shellwords.escape(file)
52
46
  "#{_pry_.config.editor} #{blocking_flag_for_editor(blocking)} #{start_line_syntax_for_editor(sanitized_file, line)}"
53
47
  end
54
48
  end
@@ -109,7 +103,7 @@ class Pry
109
103
  when /^redcar/
110
104
  "-l#{line_number} #{file_name}"
111
105
  else
112
- if windows?
106
+ if Helpers::Platform.windows?
113
107
  "#{file_name}"
114
108
  else
115
109
  "+#{line_number} #{file_name}"
@@ -130,6 +124,5 @@ class Pry
130
124
  def editor_name
131
125
  File.basename(_pry_.config.editor).split(" ").first
132
126
  end
133
-
134
127
  end
135
128
  end
@@ -1,5 +1,4 @@
1
1
  class Pry
2
-
3
2
  # As a REPL, we often want to catch any unexpected exceptions that may have
4
3
  # been raised; however we don't want to go overboard and prevent the user
5
4
  # from exiting Pry when they want to.
@@ -74,5 +73,4 @@ class Pry
74
73
  # IRB = Pry thing.
75
74
  module ExtendCommandBundle
76
75
  end
77
-
78
76
  end