pry 0.11.3 → 0.14.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +346 -2
  3. data/LICENSE +1 -1
  4. data/README.md +351 -292
  5. data/bin/pry +1 -0
  6. data/lib/pry/basic_object.rb +8 -4
  7. data/lib/pry/block_command.rb +22 -0
  8. data/lib/pry/class_command.rb +194 -0
  9. data/lib/pry/cli.rb +58 -76
  10. data/lib/pry/code/code_file.rb +33 -28
  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 +37 -33
  14. data/lib/pry/code_object.rb +41 -39
  15. data/lib/pry/color_printer.rb +47 -45
  16. data/lib/pry/command.rb +178 -374
  17. data/lib/pry/command_set.rb +89 -121
  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 +71 -59
  24. data/lib/pry/commands/cat/file_formatter.rb +55 -49
  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 -133
  32. data/lib/pry/commands/disable_pry.rb +23 -19
  33. data/lib/pry/commands/easter_eggs.rb +19 -30
  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 +184 -160
  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 +60 -43
  48. data/lib/pry/commands/ls/formatter.rb +42 -37
  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 -23
  60. data/lib/pry/commands/ls.rb +124 -105
  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 +56 -45
  69. data/lib/pry/commands/save_file.rb +45 -43
  70. data/lib/pry/commands/shell_command.rb +52 -51
  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 +192 -167
  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 -148
  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 +312 -9
  88. data/lib/pry/control_d_handler.rb +28 -0
  89. data/lib/pry/core_extensions.rb +13 -10
  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 +5 -1
  95. data/lib/pry/helpers/base_helpers.rb +58 -58
  96. data/lib/pry/helpers/command_helpers.rb +52 -62
  97. data/lib/pry/helpers/documentation_helpers.rb +21 -13
  98. data/lib/pry/helpers/options_helpers.rb +14 -7
  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 +20 -18
  102. data/lib/pry/helpers.rb +3 -0
  103. data/lib/pry/history.rb +65 -60
  104. data/lib/pry/hooks.rb +24 -15
  105. data/lib/pry/indent.rb +72 -70
  106. data/lib/pry/input_completer.rb +251 -228
  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 +18 -5
  111. data/lib/pry/method/patcher.rb +14 -5
  112. data/lib/pry/method/weird_method_locator.rb +74 -51
  113. data/lib/pry/method.rb +175 -121
  114. data/lib/pry/object_path.rb +37 -28
  115. data/lib/pry/output.rb +122 -35
  116. data/lib/pry/pager.rb +187 -180
  117. data/lib/pry/prompt.rb +213 -25
  118. data/lib/pry/pry_class.rb +91 -96
  119. data/lib/pry/pry_instance.rb +258 -223
  120. data/lib/pry/repl.rb +49 -25
  121. data/lib/pry/repl_file_loader.rb +27 -22
  122. data/lib/pry/ring.rb +89 -0
  123. data/lib/pry/slop/commands.rb +164 -170
  124. data/lib/pry/slop/option.rb +172 -170
  125. data/lib/pry/slop.rb +567 -556
  126. data/lib/pry/syntax_highlighter.rb +26 -0
  127. data/lib/pry/system_command_handler.rb +17 -0
  128. data/lib/pry/testable/evalable.rb +21 -12
  129. data/lib/pry/testable/mockable.rb +18 -10
  130. data/lib/pry/testable/pry_tester.rb +71 -56
  131. data/lib/pry/testable/utility.rb +29 -21
  132. data/lib/pry/testable/variables.rb +49 -43
  133. data/lib/pry/testable.rb +59 -61
  134. data/lib/pry/version.rb +3 -1
  135. data/lib/pry/warning.rb +20 -0
  136. data/lib/pry/wrapped_module/candidate.rb +31 -23
  137. data/lib/pry/wrapped_module.rb +63 -59
  138. data/lib/pry.rb +132 -149
  139. metadata +39 -51
  140. data/lib/pry/commands/disabled_commands.rb +0 -2
  141. data/lib/pry/commands/gem_cd.rb +0 -26
  142. data/lib/pry/commands/gem_install.rb +0 -32
  143. data/lib/pry/commands/gem_list.rb +0 -33
  144. data/lib/pry/commands/gem_open.rb +0 -29
  145. data/lib/pry/commands/gem_readme.rb +0 -25
  146. data/lib/pry/commands/gem_search.rb +0 -40
  147. data/lib/pry/commands/gist.rb +0 -101
  148. data/lib/pry/commands/install_command.rb +0 -53
  149. data/lib/pry/commands/list_prompts.rb +0 -35
  150. data/lib/pry/commands/simple_prompt.rb +0 -22
  151. data/lib/pry/commands.rb +0 -6
  152. data/lib/pry/config/behavior.rb +0 -231
  153. data/lib/pry/config/convenience.rb +0 -25
  154. data/lib/pry/config/default.rb +0 -149
  155. data/lib/pry/config/memoization.rb +0 -44
  156. data/lib/pry/history_array.rb +0 -121
  157. data/lib/pry/platform.rb +0 -93
  158. data/lib/pry/plugins.rb +0 -118
  159. data/lib/pry/rbx_path.rb +0 -22
  160. data/lib/pry/rubygem.rb +0 -84
  161. data/lib/pry/terminal.rb +0 -90
@@ -1,208 +1,210 @@
1
- class Pry::Slop
2
- class Option
3
-
4
- # The default Hash of configuration options this class uses.
5
- DEFAULT_OPTIONS = {
6
- :argument => false,
7
- :optional_argument => false,
8
- :tail => false,
9
- :default => nil,
10
- :callback => nil,
11
- :delimiter => ',',
12
- :limit => 0,
13
- :match => nil,
14
- :optional => true,
15
- :required => false,
16
- :as => String,
17
- :autocreated => false
18
- }
19
-
20
- attr_reader :short, :long, :description, :config, :types
21
- attr_accessor :count, :argument_in_value
22
-
23
- # Incapsulate internal option information, mainly used to store
24
- # option specific configuration data, most of the meat of this
25
- # class is found in the #value method.
26
- #
27
- # slop - The instance of Slop tied to this Option.
28
- # short - The String or Symbol short flag.
29
- # long - The String or Symbol long flag.
30
- # description - The String description text.
31
- # config - A Hash of configuration options.
32
- # block - An optional block used as a callback.
33
- def initialize(slop, short, long, description, config = {}, &block)
34
- @slop = slop
35
- @short = short
36
- @long = long
37
- @description = description
38
- @config = DEFAULT_OPTIONS.merge(config)
39
- @count = 0
40
- @callback = block_given? ? block : config[:callback]
41
- @value = nil
42
-
43
- @types = {
44
- :string => proc { |v| v.to_s },
45
- :symbol => proc { |v| v.to_sym },
46
- :integer => proc { |v| value_to_integer(v) },
47
- :float => proc { |v| value_to_float(v) },
48
- :range => proc { |v| value_to_range(v) },
49
- :count => proc { |v| @count }
50
- }
51
-
52
- if long && long.size > @slop.config[:longest_flag]
53
- @slop.config[:longest_flag] = long.size
54
- end
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Slop
5
+ class Option
6
+ # The default Hash of configuration options this class uses.
7
+ DEFAULT_OPTIONS = {
8
+ argument: false,
9
+ optional_argument: false,
10
+ tail: false,
11
+ default: nil,
12
+ callback: nil,
13
+ delimiter: ',',
14
+ limit: 0,
15
+ match: nil,
16
+ optional: true,
17
+ required: false,
18
+ as: String,
19
+ autocreated: false
20
+ }.freeze
21
+
22
+ attr_reader :short, :long, :description, :config, :types
23
+ attr_accessor :count, :argument_in_value
24
+
25
+ # Incapsulate internal option information, mainly used to store
26
+ # option specific configuration data, most of the meat of this
27
+ # class is found in the #value method.
28
+ #
29
+ # slop - The instance of Slop tied to this Option.
30
+ # short - The String or Symbol short flag.
31
+ # long - The String or Symbol long flag.
32
+ # description - The String description text.
33
+ # config - A Hash of configuration options.
34
+ # block - An optional block used as a callback.
35
+ def initialize(slop, short, long, description, config = {}, &block)
36
+ @slop = slop
37
+ @short = short
38
+ @long = long
39
+ @description = description
40
+ @config = DEFAULT_OPTIONS.merge(config)
41
+ @count = 0
42
+ @callback = block_given? ? block : config[:callback]
43
+ @value = nil
44
+
45
+ @types = {
46
+ string: proc { |v| v.to_s },
47
+ symbol: proc { |v| v.to_sym },
48
+ integer: proc { |v| value_to_integer(v) },
49
+ float: proc { |v| value_to_float(v) },
50
+ range: proc { |v| value_to_range(v) },
51
+ count: proc { @count }
52
+ }
53
+
54
+ if long && long.size > @slop.config[:longest_flag]
55
+ @slop.config[:longest_flag] = long.size
56
+ end
55
57
 
56
- @config.each_key do |key|
57
- predicate = :"#{key}?"
58
- unless self.class.method_defined? predicate
59
- self.class.__send__(:define_method, predicate) { !!@config[key] }
58
+ @config.each_key do |key|
59
+ predicate = :"#{key}?"
60
+ unless self.class.method_defined?(predicate)
61
+ self.class.__send__(:define_method, predicate) { !@config.key?(key) }
62
+ end
60
63
  end
61
64
  end
62
- end
63
65
 
64
- # Returns true if this option expects an argument.
65
- def expects_argument?
66
- config[:argument] && config[:argument] != :optional
67
- end
66
+ # Returns true if this option expects an argument.
67
+ def expects_argument?
68
+ config[:argument] && config[:argument] != :optional
69
+ end
68
70
 
69
- # Returns true if this option accepts an optional argument.
70
- def accepts_optional_argument?
71
- config[:optional_argument] || config[:argument] == :optional
72
- end
71
+ # Returns true if this option accepts an optional argument.
72
+ def accepts_optional_argument?
73
+ config[:optional_argument] || config[:argument] == :optional
74
+ end
73
75
 
74
- # Returns the String flag of this option. Preferring the long flag.
75
- def key
76
- long || short
77
- end
76
+ # Returns the String flag of this option. Preferring the long flag.
77
+ def key
78
+ long || short
79
+ end
78
80
 
79
- # Call this options callback if one exists, and it responds to call().
80
- #
81
- # Returns nothing.
82
- def call(*objects)
83
- @callback.call(*objects) if @callback.respond_to?(:call)
84
- end
81
+ # Call this options callback if one exists, and it responds to call().
82
+ #
83
+ # Returns nothing.
84
+ def call(*objects)
85
+ @callback.call(*objects) if @callback.respond_to?(:call)
86
+ end
85
87
 
86
- # Set the new argument value for this option.
87
- #
88
- # We use this setter method to handle concatenating lists. That is,
89
- # when an array type is specified and used more than once, values from
90
- # both options will be grouped together and flattened into a single array.
91
- def value=(new_value)
92
- if config[:as].to_s.downcase == 'array'
93
- @value ||= []
94
-
95
- if new_value.respond_to?(:split)
96
- @value.concat new_value.split(config[:delimiter], config[:limit])
88
+ # Set the new argument value for this option.
89
+ #
90
+ # We use this setter method to handle concatenating lists. That is,
91
+ # when an array type is specified and used more than once, values from
92
+ # both options will be grouped together and flattened into a single array.
93
+ def value=(new_value)
94
+ if config[:as].to_s.casecmp('array') == 0
95
+ @value ||= []
96
+
97
+ if new_value.respond_to?(:split)
98
+ @value.concat new_value.split(config[:delimiter], config[:limit])
99
+ end
100
+ else
101
+ @value = new_value
97
102
  end
98
- else
99
- @value = new_value
100
103
  end
101
- end
102
104
 
103
- # Fetch the argument value for this option.
104
- #
105
- # Returns the Object once any type conversions have taken place.
106
- def value
107
- value = @value.nil? ? config[:default] : @value
105
+ # Fetch the argument value for this option.
106
+ #
107
+ # Returns the Object once any type conversions have taken place.
108
+ def value
109
+ value = @value.nil? ? config[:default] : @value
108
110
 
109
- if [true, false, nil].include?(value) && config[:as].to_s != 'count'
110
- return value
111
- end
111
+ return value if [true, false, nil].include?(value) && config[:as].to_s != 'count'
112
112
 
113
- type = config[:as]
114
- if type.respond_to?(:call)
115
- type.call(value)
116
- else
117
- if callable = types[type.to_s.downcase.to_sym]
113
+ type = config[:as]
114
+ if type.respond_to?(:call)
115
+ type.call(value)
116
+ elsif (callable = types[type.to_s.downcase.to_sym])
118
117
  callable.call(value)
119
118
  else
120
119
  value
121
120
  end
122
121
  end
123
- end
124
122
 
125
- # Returns the help String for this option.
126
- def to_s
127
- return config[:help] if config[:help].respond_to?(:to_str)
123
+ # Returns the help String for this option.
124
+ def to_s
125
+ return config[:help] if config[:help].respond_to?(:to_str)
128
126
 
129
- out = " #{short ? "-#{short}, " : ' ' * 4}"
127
+ out = " #{short ? "-#{short}, " : ' ' * 4}"
130
128
 
131
- if long
132
- out << "--#{long}"
133
- size = long.size
134
- diff = @slop.config[:longest_flag] - size
135
- out << (' ' * (diff + 6))
136
- else
137
- out << (' ' * (@slop.config[:longest_flag] + 8))
129
+ if long
130
+ out += "--#{long}"
131
+ size = long.size
132
+ diff = @slop.config[:longest_flag] - size
133
+ out += (' ' * (diff + 6))
134
+ else
135
+ out += (' ' * (@slop.config[:longest_flag] + 8))
136
+ end
137
+
138
+ "#{out}#{description}"
138
139
  end
140
+ alias help to_s
139
141
 
140
- "#{out}#{description}"
141
- end
142
- alias help to_s
142
+ # Returns the String inspection text.
143
+ def inspect
144
+ "#<Slop::Option [-#{short} | --#{long}" \
145
+ "#{'=' if expects_argument?}#{'=?' if accepts_optional_argument?}]" \
146
+ " (#{description}) #{config.inspect}"
147
+ end
143
148
 
144
- # Returns the String inspection text.
145
- def inspect
146
- "#<Slop::Option [-#{short} | --#{long}" +
147
- "#{'=' if expects_argument?}#{'=?' if accepts_optional_argument?}]" +
148
- " (#{description}) #{config.inspect}"
149
- end
149
+ private
150
150
 
151
- private
152
-
153
- # Convert an object to an Integer if possible.
154
- #
155
- # value - The Object we want to convert to an integer.
156
- #
157
- # Returns the Integer value if possible to convert, else a zero.
158
- def value_to_integer(value)
159
- if @slop.strict?
160
- begin
161
- Integer(value.to_s, 10)
162
- rescue ArgumentError
163
- raise InvalidArgumentError, "#{value} could not be coerced into Integer"
151
+ # Convert an object to an Integer if possible.
152
+ #
153
+ # value - The Object we want to convert to an integer.
154
+ #
155
+ # Returns the Integer value if possible to convert, else a zero.
156
+ def value_to_integer(value)
157
+ if @slop.strict?
158
+ begin
159
+ Integer(value.to_s, 10)
160
+ rescue ArgumentError
161
+ raise InvalidArgumentError, "#{value} could not be coerced into Integer"
162
+ end
163
+ else
164
+ value.to_s.to_i
164
165
  end
165
- else
166
- value.to_s.to_i
167
166
  end
168
- end
169
167
 
170
- # Convert an object to a Float if possible.
171
- #
172
- # value - The Object we want to convert to a float.
173
- #
174
- # Returns the Float value if possible to convert, else a zero.
175
- def value_to_float(value)
176
- if @slop.strict?
177
- begin
178
- Float(value.to_s)
179
- rescue ArgumentError
180
- raise InvalidArgumentError, "#{value} could not be coerced into Float"
168
+ # Convert an object to a Float if possible.
169
+ #
170
+ # value - The Object we want to convert to a float.
171
+ #
172
+ # Returns the Float value if possible to convert, else a zero.
173
+ def value_to_float(value)
174
+ if @slop.strict?
175
+ begin
176
+ Float(value.to_s)
177
+ rescue ArgumentError
178
+ raise InvalidArgumentError, "#{value} could not be coerced into Float"
179
+ end
180
+ else
181
+ value.to_s.to_f
181
182
  end
182
- else
183
- value.to_s.to_f
184
183
  end
185
- end
186
184
 
187
- # Convert an object to a Range if possible.
188
- #
189
- # value - The Object we want to convert to a range.
190
- #
191
- # Returns the Range value if one could be found, else the original object.
192
- def value_to_range(value)
193
- case value.to_s
194
- when /\A(\-?\d+)\z/
195
- Range.new($1.to_i, $1.to_i)
196
- when /\A(-?\d+?)(\.\.\.?|-|,)(-?\d+)\z/
197
- Range.new($1.to_i, $3.to_i, $2 == '...')
198
- else
199
- if @slop.strict?
200
- raise InvalidArgumentError, "#{value} could not be coerced into Range"
185
+ # Convert an object to a Range if possible.
186
+ #
187
+ # value - The Object we want to convert to a range.
188
+ #
189
+ # Returns the Range value if one could be found, else the original object.
190
+ def value_to_range(value)
191
+ case value.to_s
192
+ when /\A(\-?\d+)\z/
193
+ Range.new(Regexp.last_match(1).to_i, Regexp.last_match(1).to_i)
194
+ when /\A(-?\d+?)(\.\.\.?|-|,)(-?\d+)\z/
195
+ Range.new(
196
+ Regexp.last_match(1).to_i,
197
+ Regexp.last_match(3).to_i,
198
+ Regexp.last_match(2) == '...'
199
+ )
201
200
  else
201
+ if @slop.strict?
202
+ raise InvalidArgumentError, "#{value} could not be coerced into Range"
203
+ end
204
+
202
205
  value
203
206
  end
204
207
  end
205
208
  end
206
-
207
209
  end
208
210
  end