pry 0.12.0-java → 0.14.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +162 -1
  3. data/LICENSE +1 -1
  4. data/README.md +331 -269
  5. data/bin/pry +5 -0
  6. data/lib/pry.rb +132 -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 +43 -51
  11. data/lib/pry/code.rb +40 -28
  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 +22 -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 +80 -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 +110 -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 +307 -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 +186 -180
  118. data/lib/pry/prompt.rb +123 -54
  119. data/lib/pry/pry_class.rb +61 -103
  120. data/lib/pry/pry_instance.rb +217 -215
  121. data/lib/pry/repl.rb +18 -22
  122. data/lib/pry/repl_file_loader.rb +27 -21
  123. data/lib/pry/ring.rb +11 -6
  124. data/lib/pry/slop.rb +574 -563
  125. data/lib/pry/slop/commands.rb +164 -169
  126. data/lib/pry/slop/option.rb +172 -168
  127. data/lib/pry/syntax_highlighter.rb +26 -0
  128. data/lib/pry/system_command_handler.rb +17 -0
  129. data/lib/pry/testable.rb +59 -61
  130. data/lib/pry/testable/evalable.rb +21 -12
  131. data/lib/pry/testable/mockable.rb +18 -10
  132. data/lib/pry/testable/pry_tester.rb +71 -56
  133. data/lib/pry/testable/utility.rb +29 -21
  134. data/lib/pry/testable/variables.rb +49 -43
  135. data/lib/pry/version.rb +3 -1
  136. data/lib/pry/warning.rb +27 -0
  137. data/lib/pry/wrapped_module.rb +51 -42
  138. data/lib/pry/wrapped_module/candidate.rb +21 -14
  139. metadata +37 -37
  140. data/lib/pry/commands.rb +0 -6
  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/gem_readme.rb +0 -25
  147. data/lib/pry/commands/gem_search.rb +0 -40
  148. data/lib/pry/commands/gem_stats.rb +0 -83
  149. data/lib/pry/commands/gist.rb +0 -102
  150. data/lib/pry/commands/install_command.rb +0 -54
  151. data/lib/pry/config/behavior.rb +0 -255
  152. data/lib/pry/config/convenience.rb +0 -28
  153. data/lib/pry/config/default.rb +0 -159
  154. data/lib/pry/config/memoization.rb +0 -48
  155. data/lib/pry/platform.rb +0 -91
  156. data/lib/pry/plugins.rb +0 -122
  157. data/lib/pry/rubygem.rb +0 -84
  158. data/lib/pry/terminal.rb +0 -91
@@ -1,255 +0,0 @@
1
- class Pry
2
- class Config < Pry::BasicObject
3
- module Behavior
4
- ASSIGNMENT = "=".freeze
5
- NODUP = [TrueClass, FalseClass, NilClass, Symbol, Numeric, Module, Proc].freeze
6
- INSPECT_REGEXP = /#{Regexp.escape "default=#<"}/
7
- ReservedKeyError = Class.new(RuntimeError)
8
-
9
- module Builder
10
- #
11
- # Returns a new Behavior, non-recursively (unlike {#from_hash}).
12
- #
13
- # @param
14
- # (see #from_hash)
15
- #
16
- # @return
17
- # (see #from_hash)
18
- #
19
- def assign(attributes, default = nil)
20
- new(default).tap do |behavior|
21
- behavior.merge!(attributes)
22
- end
23
- end
24
-
25
- #
26
- # Returns a new Behavior, recursively walking attributes.
27
- #
28
- # @param [Hash] attributes
29
- # a hash to initialize an instance of self with.
30
- #
31
- # @param [Pry::Config, nil] default
32
- # a default, or nil for none.
33
- #
34
- # @return [Pry::Config]
35
- # returns an instance of self.
36
- #
37
- def from_hash(attributes, default = nil)
38
- new(default).tap do |config|
39
- attributes.each do |key,value|
40
- config[key] = Hash === value ? from_hash(value, nil) : value
41
- end
42
- end
43
- end
44
- end
45
-
46
- def self.included(klass)
47
- klass.extend(Builder)
48
- end
49
-
50
- def initialize(default = Pry.config)
51
- @default = default
52
- @lookup = {}
53
- @reserved_keys = methods.map(&:to_s).freeze
54
- end
55
-
56
- #
57
- # @return [Pry::Config::Behavior]
58
- # returns the default used incase a key isn't found in self.
59
- #
60
- def default
61
- @default
62
- end
63
-
64
- #
65
- # @param [String] key
66
- # a key (as a String)
67
- #
68
- # @return [Object, BasicObject]
69
- # returns an object from self or one of its defaults.
70
- #
71
- def [](key)
72
- key = key.to_s
73
- key?(key) ? @lookup[key] : (@default and @default[key])
74
- end
75
-
76
- #
77
- # Add a key and value pair to self.
78
- #
79
- # @param [String] key
80
- # a key (as a String).
81
- #
82
- # @param [Object,BasicObject] value
83
- # a value.
84
- #
85
- # @raise [Pry::Config::ReservedKeyError]
86
- # when 'key' is a reserved key name.
87
- #
88
- def []=(key, value)
89
- key = key.to_s
90
- if @reserved_keys.include?(key)
91
- raise ReservedKeyError, "It is not possible to use '#{key}' as a key name, please choose a different key name."
92
- end
93
-
94
- __push(key,value)
95
- end
96
-
97
- #
98
- # Removes a key from self.
99
- #
100
- # @param [String] key
101
- # a key (as a String)
102
- #
103
- # @return [void]
104
- #
105
- def forget(key)
106
- key = key.to_s
107
- __remove(key)
108
- end
109
-
110
- #
111
- # @param [Hash, #to_h, #to_hash] other
112
- # a hash to merge into self.
113
- #
114
- # @return [void]
115
- #
116
- def merge!(other)
117
- other = __try_convert_to_hash(other)
118
- raise TypeError, "unable to convert argument into a Hash" unless other
119
-
120
- other.each do |key, value|
121
- self[key] = value
122
- end
123
- end
124
-
125
- #
126
- # @param [Hash, #to_h, #to_hash] other
127
- # a hash to compare against the lookup table of self.
128
- #
129
- def ==(other)
130
- @lookup == __try_convert_to_hash(other)
131
- end
132
- alias_method :eql?, :==
133
-
134
- #
135
- # @param [String] key
136
- # a key (as a String)
137
- #
138
- # @return [Boolean]
139
- # returns true when "key" is a member of self.
140
- #
141
- def key?(key)
142
- key = key.to_s
143
- @lookup.key?(key)
144
- end
145
-
146
- #
147
- # Clear the lookup table of self.
148
- #
149
- # @return [void]
150
- #
151
- def clear
152
- @lookup.clear
153
- true
154
- end
155
-
156
- #
157
- # @return [Array<String>]
158
- # returns an array of keys in self.
159
- #
160
- def keys
161
- @lookup.keys
162
- end
163
-
164
- def eager_load!
165
- default = @default
166
- while default
167
- default.memoized_methods.each { |method| self[key] = default.public_send(key) } if default.respond_to?(:memoized_methods)
168
- default = @default.default
169
- end
170
- end
171
-
172
- def last_default
173
- last = @default
174
- last = last.default while last and last.default
175
- last
176
- end
177
-
178
- #
179
- # @return [Hash]
180
- # returns a duplicate copy of the lookup table used by self.
181
- #
182
- def to_hash
183
- @lookup.dup
184
- end
185
- alias_method :to_h, :to_hash
186
-
187
- def inspect
188
- key_str = keys.map { |key| "'#{key}'" }.join(",")
189
- "#<#{__clip_inspect(self)} keys=[#{key_str}] default=#{@default.inspect}>"
190
- end
191
-
192
- def pretty_print(q)
193
- q.text inspect[1..-1].gsub(INSPECT_REGEXP, "default=<")
194
- end
195
-
196
- def method_missing(name, *args, &block)
197
- key = name.to_s
198
- if key[-1] == ASSIGNMENT
199
- short_key = key[0..-2]
200
- self[short_key] = args[0]
201
- elsif key?(key)
202
- self[key]
203
- elsif @default.respond_to?(name)
204
- value = @default.public_send(name, *args, &block)
205
- self[key] = __dup(value)
206
- else
207
- nil
208
- end
209
- end
210
-
211
- def respond_to_missing?(key, include_all = false)
212
- key = key.to_s.chomp(ASSIGNMENT)
213
- key?(key) or @default.respond_to?(key) or super(key, include_all)
214
- end
215
-
216
- private
217
-
218
- def __clip_inspect(obj)
219
- "#{obj.class}:0x%x" % obj.object_id
220
- end
221
-
222
- def __try_convert_to_hash(obj)
223
- if Hash === obj
224
- obj
225
- elsif obj.respond_to?(:to_h)
226
- obj.to_h
227
- elsif obj.respond_to?(:to_hash)
228
- obj.to_hash
229
- else
230
- nil
231
- end
232
- end
233
-
234
- def __dup(value)
235
- if NODUP.any? { |klass| klass === value }
236
- value
237
- else
238
- value.dup
239
- end
240
- end
241
-
242
- def __push(key,value)
243
- unless singleton_class.method_defined? key
244
- define_singleton_method(key) { self[key] }
245
- define_singleton_method("#{key}=") { |val| @lookup[key] = val }
246
- end
247
- @lookup[key] = value
248
- end
249
-
250
- def __remove(key)
251
- @lookup.delete(key)
252
- end
253
- end
254
- end
255
- end
@@ -1,28 +0,0 @@
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
- ]
17
-
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
26
- end
27
- end
28
- end
@@ -1,159 +0,0 @@
1
- class Pry
2
- class Config < Pry::BasicObject
3
- class Default
4
- include Config::Behavior
5
- include Config::Memoization
6
-
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)
142
- end
143
-
144
- private
145
-
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
158
- end
159
- end
@@ -1,48 +0,0 @@
1
- class Pry
2
- class Config < Pry::BasicObject
3
- module Memoization
4
- MEMOIZED_METHODS = Hash.new { |h,k| h[k] = [] }
5
-
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
32
- end
33
- end
34
-
35
- def self.included(mod)
36
- mod.extend(ClassMethods)
37
- end
38
-
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
47
- end
48
- end