pry 0.11.3 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +139 -1
  3. data/LICENSE +1 -1
  4. data/README.md +13 -30
  5. data/bin/pry +0 -4
  6. data/lib/pry.rb +17 -47
  7. data/lib/pry/cli.rb +17 -24
  8. data/lib/pry/code.rb +6 -6
  9. data/lib/pry/code/code_file.rb +5 -4
  10. data/lib/pry/code/code_range.rb +3 -3
  11. data/lib/pry/code/loc.rb +14 -8
  12. data/lib/pry/code_object.rb +4 -4
  13. data/lib/pry/color_printer.rb +1 -0
  14. data/lib/pry/command.rb +36 -29
  15. data/lib/pry/command_set.rb +17 -52
  16. data/lib/pry/commands/amend_line.rb +3 -4
  17. data/lib/pry/commands/bang.rb +1 -1
  18. data/lib/pry/commands/cat.rb +7 -6
  19. data/lib/pry/commands/cat/exception_formatter.rb +9 -8
  20. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  21. data/lib/pry/commands/change_prompt.rb +29 -9
  22. data/lib/pry/commands/clear_screen.rb +14 -0
  23. data/lib/pry/commands/code_collector.rb +9 -9
  24. data/lib/pry/commands/easter_eggs.rb +3 -3
  25. data/lib/pry/commands/edit.rb +8 -7
  26. data/lib/pry/commands/exit.rb +2 -1
  27. data/lib/pry/commands/find_method.rb +11 -13
  28. data/lib/pry/commands/gem_cd.rb +1 -1
  29. data/lib/pry/commands/gem_install.rb +2 -2
  30. data/lib/pry/commands/gem_list.rb +2 -2
  31. data/lib/pry/commands/gem_open.rb +1 -1
  32. data/lib/pry/commands/gem_search.rb +2 -2
  33. data/lib/pry/commands/gem_stats.rb +83 -0
  34. data/lib/pry/commands/gist.rb +7 -6
  35. data/lib/pry/commands/help.rb +3 -3
  36. data/lib/pry/commands/hist.rb +9 -8
  37. data/lib/pry/commands/import_set.rb +2 -1
  38. data/lib/pry/commands/install_command.rb +7 -6
  39. data/lib/pry/commands/list_inspectors.rb +2 -2
  40. data/lib/pry/commands/ls.rb +27 -30
  41. data/lib/pry/commands/ls/constants.rb +4 -4
  42. data/lib/pry/commands/ls/formatter.rb +3 -2
  43. data/lib/pry/commands/ls/globals.rb +0 -2
  44. data/lib/pry/commands/ls/grep.rb +0 -2
  45. data/lib/pry/commands/ls/instance_vars.rb +0 -1
  46. data/lib/pry/commands/ls/local_names.rb +0 -2
  47. data/lib/pry/commands/ls/local_vars.rb +0 -2
  48. data/lib/pry/commands/ls/ls_entity.rb +0 -1
  49. data/lib/pry/commands/ls/methods.rb +0 -3
  50. data/lib/pry/commands/ls/methods_helper.rb +1 -1
  51. data/lib/pry/commands/ls/self_methods.rb +0 -1
  52. data/lib/pry/commands/play.rb +1 -2
  53. data/lib/pry/commands/pry_backtrace.rb +1 -1
  54. data/lib/pry/commands/raise_up.rb +2 -1
  55. data/lib/pry/commands/ri.rb +5 -4
  56. data/lib/pry/commands/shell_command.rb +3 -2
  57. data/lib/pry/commands/shell_mode.rb +6 -6
  58. data/lib/pry/commands/show_doc.rb +5 -7
  59. data/lib/pry/commands/show_info.rb +25 -18
  60. data/lib/pry/commands/show_source.rb +5 -2
  61. data/lib/pry/commands/stat.rb +1 -1
  62. data/lib/pry/commands/watch_expression.rb +9 -7
  63. data/lib/pry/commands/whereami.rb +4 -4
  64. data/lib/pry/commands/wtf.rb +15 -2
  65. data/lib/pry/config.rb +33 -9
  66. data/lib/pry/config/behavior.rb +229 -205
  67. data/lib/pry/config/convenience.rb +24 -21
  68. data/lib/pry/config/default.rb +153 -143
  69. data/lib/pry/config/memoization.rb +41 -37
  70. data/lib/pry/core_extensions.rb +4 -3
  71. data/lib/pry/editor.rb +5 -12
  72. data/lib/pry/exceptions.rb +0 -2
  73. data/lib/pry/helpers.rb +1 -0
  74. data/lib/pry/helpers/base_helpers.rb +133 -4
  75. data/lib/pry/helpers/command_helpers.rb +5 -4
  76. data/lib/pry/helpers/documentation_helpers.rb +2 -2
  77. data/lib/pry/helpers/options_helpers.rb +5 -5
  78. data/lib/pry/helpers/platform.rb +58 -0
  79. data/lib/pry/helpers/table.rb +20 -15
  80. data/lib/pry/helpers/text.rb +3 -4
  81. data/lib/pry/history.rb +21 -8
  82. data/lib/pry/hooks.rb +3 -3
  83. data/lib/pry/indent.rb +15 -17
  84. data/lib/pry/input_completer.rb +12 -7
  85. data/lib/pry/input_lock.rb +0 -2
  86. data/lib/pry/last_exception.rb +1 -1
  87. data/lib/pry/method.rb +37 -31
  88. data/lib/pry/method/disowned.rb +2 -1
  89. data/lib/pry/method/patcher.rb +2 -2
  90. data/lib/pry/method/weird_method_locator.rb +7 -8
  91. data/lib/pry/object_path.rb +5 -4
  92. data/lib/pry/output.rb +3 -2
  93. data/lib/pry/pager.rb +4 -3
  94. data/lib/pry/platform.rb +79 -81
  95. data/lib/pry/plugins.rb +7 -3
  96. data/lib/pry/prompt.rb +144 -25
  97. data/lib/pry/pry_class.rb +53 -29
  98. data/lib/pry/pry_instance.rb +88 -55
  99. data/lib/pry/repl.rb +33 -4
  100. data/lib/pry/repl_file_loader.rb +1 -2
  101. data/lib/pry/ring.rb +84 -0
  102. data/lib/pry/rubygem.rb +6 -6
  103. data/lib/pry/slop.rb +17 -17
  104. data/lib/pry/slop/commands.rb +3 -4
  105. data/lib/pry/slop/option.rb +19 -21
  106. data/lib/pry/terminal.rb +2 -1
  107. data/lib/pry/testable/mockable.rb +2 -2
  108. data/lib/pry/testable/pry_tester.rb +1 -1
  109. data/lib/pry/testable/utility.rb +2 -2
  110. data/lib/pry/testable/variables.rb +1 -1
  111. data/lib/pry/version.rb +1 -1
  112. data/lib/pry/wrapped_module.rb +15 -15
  113. data/lib/pry/wrapped_module/candidate.rb +2 -2
  114. metadata +17 -29
  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,25 +1,28 @@
1
- module Pry::Config::Convenience
2
- SHORTCUTS = [
3
- :input,
4
- :output,
5
- :commands,
6
- :print,
7
- :exception_handler,
8
- :hooks,
9
- :color,
10
- :pager,
11
- :editor,
12
- :memory_size,
13
- :extra_sticky_locals
14
- ]
1
+ class Pry
2
+ class Config < Pry::BasicObject
3
+ module Convenience
4
+ SHORTCUTS = [
5
+ :input,
6
+ :output,
7
+ :commands,
8
+ :print,
9
+ :exception_handler,
10
+ :hooks,
11
+ :color,
12
+ :pager,
13
+ :editor,
14
+ :memory_size,
15
+ :extra_sticky_locals
16
+ ]
15
17
 
16
-
17
- def config_shortcut(*names)
18
- names.each do |name|
19
- reader = name
20
- setter = "#{name}="
21
- define_method(reader) { config.public_send(name) }
22
- define_method(setter) { |value| config.public_send(setter, value) }
18
+ def config_shortcut(*names)
19
+ names.each do |name|
20
+ reader = name
21
+ setter = "#{name}="
22
+ define_method(reader) { config.public_send(name) }
23
+ define_method(setter) { |value| config.public_send(setter, value) }
24
+ end
25
+ end
23
26
  end
24
27
  end
25
28
  end
@@ -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
@@ -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`).