super-smart-mod 0.0.1

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 (143) hide show
  1. checksums.yaml +7 -0
  2. data/pry-0.16.0/CHANGELOG.md +1211 -0
  3. data/pry-0.16.0/LICENSE +25 -0
  4. data/pry-0.16.0/README.md +469 -0
  5. data/pry-0.16.0/bin/pry +13 -0
  6. data/pry-0.16.0/lib/pry/basic_object.rb +10 -0
  7. data/pry-0.16.0/lib/pry/block_command.rb +22 -0
  8. data/pry-0.16.0/lib/pry/class_command.rb +194 -0
  9. data/pry-0.16.0/lib/pry/cli.rb +211 -0
  10. data/pry-0.16.0/lib/pry/code/code_file.rb +114 -0
  11. data/pry-0.16.0/lib/pry/code/code_range.rb +73 -0
  12. data/pry-0.16.0/lib/pry/code/loc.rb +105 -0
  13. data/pry-0.16.0/lib/pry/code.rb +357 -0
  14. data/pry-0.16.0/lib/pry/code_object.rb +197 -0
  15. data/pry-0.16.0/lib/pry/color_printer.rb +66 -0
  16. data/pry-0.16.0/lib/pry/command.rb +520 -0
  17. data/pry-0.16.0/lib/pry/command_set.rb +418 -0
  18. data/pry-0.16.0/lib/pry/command_state.rb +36 -0
  19. data/pry-0.16.0/lib/pry/commands/amend_line.rb +103 -0
  20. data/pry-0.16.0/lib/pry/commands/bang.rb +24 -0
  21. data/pry-0.16.0/lib/pry/commands/bang_pry.rb +21 -0
  22. data/pry-0.16.0/lib/pry/commands/cat/abstract_formatter.rb +32 -0
  23. data/pry-0.16.0/lib/pry/commands/cat/exception_formatter.rb +90 -0
  24. data/pry-0.16.0/lib/pry/commands/cat/file_formatter.rb +77 -0
  25. data/pry-0.16.0/lib/pry/commands/cat/input_expression_formatter.rb +48 -0
  26. data/pry-0.16.0/lib/pry/commands/cat.rb +70 -0
  27. data/pry-0.16.0/lib/pry/commands/cd.rb +48 -0
  28. data/pry-0.16.0/lib/pry/commands/change_inspector.rb +34 -0
  29. data/pry-0.16.0/lib/pry/commands/change_prompt.rb +51 -0
  30. data/pry-0.16.0/lib/pry/commands/clear_screen.rb +20 -0
  31. data/pry-0.16.0/lib/pry/commands/code_collector.rb +182 -0
  32. data/pry-0.16.0/lib/pry/commands/disable_pry.rb +31 -0
  33. data/pry-0.16.0/lib/pry/commands/easter_eggs.rb +101 -0
  34. data/pry-0.16.0/lib/pry/commands/edit/exception_patcher.rb +29 -0
  35. data/pry-0.16.0/lib/pry/commands/edit/file_and_line_locator.rb +47 -0
  36. data/pry-0.16.0/lib/pry/commands/edit.rb +225 -0
  37. data/pry-0.16.0/lib/pry/commands/exit.rb +47 -0
  38. data/pry-0.16.0/lib/pry/commands/exit_all.rb +33 -0
  39. data/pry-0.16.0/lib/pry/commands/exit_program.rb +27 -0
  40. data/pry-0.16.0/lib/pry/commands/find_method.rb +199 -0
  41. data/pry-0.16.0/lib/pry/commands/fix_indent.rb +23 -0
  42. data/pry-0.16.0/lib/pry/commands/help.rb +171 -0
  43. data/pry-0.16.0/lib/pry/commands/hist.rb +182 -0
  44. data/pry-0.16.0/lib/pry/commands/import_set.rb +27 -0
  45. data/pry-0.16.0/lib/pry/commands/jump_to.rb +33 -0
  46. data/pry-0.16.0/lib/pry/commands/list_inspectors.rb +42 -0
  47. data/pry-0.16.0/lib/pry/commands/ls/config.rb +54 -0
  48. data/pry-0.16.0/lib/pry/commands/ls/constants.rb +75 -0
  49. data/pry-0.16.0/lib/pry/commands/ls/formatter.rb +55 -0
  50. data/pry-0.16.0/lib/pry/commands/ls/globals.rb +50 -0
  51. data/pry-0.16.0/lib/pry/commands/ls/grep.rb +23 -0
  52. data/pry-0.16.0/lib/pry/commands/ls/instance_vars.rb +40 -0
  53. data/pry-0.16.0/lib/pry/commands/ls/interrogatable.rb +24 -0
  54. data/pry-0.16.0/lib/pry/commands/ls/jruby_hacks.rb +55 -0
  55. data/pry-0.16.0/lib/pry/commands/ls/local_names.rb +37 -0
  56. data/pry-0.16.0/lib/pry/commands/ls/local_vars.rb +47 -0
  57. data/pry-0.16.0/lib/pry/commands/ls/ls_entity.rb +65 -0
  58. data/pry-0.16.0/lib/pry/commands/ls/methods.rb +55 -0
  59. data/pry-0.16.0/lib/pry/commands/ls/methods_helper.rb +50 -0
  60. data/pry-0.16.0/lib/pry/commands/ls/self_methods.rb +34 -0
  61. data/pry-0.16.0/lib/pry/commands/ls.rb +114 -0
  62. data/pry-0.16.0/lib/pry/commands/nesting.rb +29 -0
  63. data/pry-0.16.0/lib/pry/commands/play.rb +113 -0
  64. data/pry-0.16.0/lib/pry/commands/pry_backtrace.rb +30 -0
  65. data/pry-0.16.0/lib/pry/commands/pry_version.rb +21 -0
  66. data/pry-0.16.0/lib/pry/commands/raise_up.rb +38 -0
  67. data/pry-0.16.0/lib/pry/commands/reload_code.rb +74 -0
  68. data/pry-0.16.0/lib/pry/commands/reset.rb +22 -0
  69. data/pry-0.16.0/lib/pry/commands/ri.rb +75 -0
  70. data/pry-0.16.0/lib/pry/commands/save_file.rb +63 -0
  71. data/pry-0.16.0/lib/pry/commands/shell_command.rb +75 -0
  72. data/pry-0.16.0/lib/pry/commands/shell_mode.rb +30 -0
  73. data/pry-0.16.0/lib/pry/commands/show_doc.rb +84 -0
  74. data/pry-0.16.0/lib/pry/commands/show_info.rb +234 -0
  75. data/pry-0.16.0/lib/pry/commands/show_input.rb +22 -0
  76. data/pry-0.16.0/lib/pry/commands/show_source.rb +57 -0
  77. data/pry-0.16.0/lib/pry/commands/stat.rb +44 -0
  78. data/pry-0.16.0/lib/pry/commands/switch_to.rb +29 -0
  79. data/pry-0.16.0/lib/pry/commands/toggle_color.rb +28 -0
  80. data/pry-0.16.0/lib/pry/commands/watch_expression/expression.rb +43 -0
  81. data/pry-0.16.0/lib/pry/commands/watch_expression.rb +108 -0
  82. data/pry-0.16.0/lib/pry/commands/whereami.rb +205 -0
  83. data/pry-0.16.0/lib/pry/commands/wtf.rb +95 -0
  84. data/pry-0.16.0/lib/pry/config/attributable.rb +22 -0
  85. data/pry-0.16.0/lib/pry/config/lazy_value.rb +29 -0
  86. data/pry-0.16.0/lib/pry/config/memoized_value.rb +34 -0
  87. data/pry-0.16.0/lib/pry/config/value.rb +24 -0
  88. data/pry-0.16.0/lib/pry/config.rb +321 -0
  89. data/pry-0.16.0/lib/pry/control_d_handler.rb +28 -0
  90. data/pry-0.16.0/lib/pry/core_extensions.rb +144 -0
  91. data/pry-0.16.0/lib/pry/editor.rb +157 -0
  92. data/pry-0.16.0/lib/pry/env.rb +18 -0
  93. data/pry-0.16.0/lib/pry/exception_handler.rb +48 -0
  94. data/pry-0.16.0/lib/pry/exceptions.rb +73 -0
  95. data/pry-0.16.0/lib/pry/forwardable.rb +27 -0
  96. data/pry-0.16.0/lib/pry/helpers/base_helpers.rb +71 -0
  97. data/pry-0.16.0/lib/pry/helpers/command_helpers.rb +146 -0
  98. data/pry-0.16.0/lib/pry/helpers/documentation_helpers.rb +84 -0
  99. data/pry-0.16.0/lib/pry/helpers/options_helpers.rb +34 -0
  100. data/pry-0.16.0/lib/pry/helpers/platform.rb +55 -0
  101. data/pry-0.16.0/lib/pry/helpers/table.rb +121 -0
  102. data/pry-0.16.0/lib/pry/helpers/text.rb +118 -0
  103. data/pry-0.16.0/lib/pry/helpers.rb +8 -0
  104. data/pry-0.16.0/lib/pry/history.rb +153 -0
  105. data/pry-0.16.0/lib/pry/hooks.rb +180 -0
  106. data/pry-0.16.0/lib/pry/indent.rb +414 -0
  107. data/pry-0.16.0/lib/pry/input/simple_stdio.rb +13 -0
  108. data/pry-0.16.0/lib/pry/input_completer.rb +283 -0
  109. data/pry-0.16.0/lib/pry/input_lock.rb +129 -0
  110. data/pry-0.16.0/lib/pry/inspector.rb +39 -0
  111. data/pry-0.16.0/lib/pry/last_exception.rb +61 -0
  112. data/pry-0.16.0/lib/pry/method/disowned.rb +67 -0
  113. data/pry-0.16.0/lib/pry/method/patcher.rb +131 -0
  114. data/pry-0.16.0/lib/pry/method/weird_method_locator.rb +222 -0
  115. data/pry-0.16.0/lib/pry/method.rb +599 -0
  116. data/pry-0.16.0/lib/pry/object_path.rb +91 -0
  117. data/pry-0.16.0/lib/pry/output.rb +136 -0
  118. data/pry-0.16.0/lib/pry/pager.rb +249 -0
  119. data/pry-0.16.0/lib/pry/prompt.rb +214 -0
  120. data/pry-0.16.0/lib/pry/pry_class.rb +371 -0
  121. data/pry-0.16.0/lib/pry/pry_instance.rb +663 -0
  122. data/pry-0.16.0/lib/pry/repl.rb +326 -0
  123. data/pry-0.16.0/lib/pry/repl_file_loader.rb +79 -0
  124. data/pry-0.16.0/lib/pry/ring.rb +89 -0
  125. data/pry-0.16.0/lib/pry/slop/LICENSE +20 -0
  126. data/pry-0.16.0/lib/pry/slop/commands.rb +190 -0
  127. data/pry-0.16.0/lib/pry/slop/option.rb +210 -0
  128. data/pry-0.16.0/lib/pry/slop.rb +672 -0
  129. data/pry-0.16.0/lib/pry/syntax_highlighter.rb +26 -0
  130. data/pry-0.16.0/lib/pry/system_command_handler.rb +17 -0
  131. data/pry-0.16.0/lib/pry/testable/evalable.rb +24 -0
  132. data/pry-0.16.0/lib/pry/testable/mockable.rb +22 -0
  133. data/pry-0.16.0/lib/pry/testable/pry_tester.rb +88 -0
  134. data/pry-0.16.0/lib/pry/testable/utility.rb +34 -0
  135. data/pry-0.16.0/lib/pry/testable/variables.rb +52 -0
  136. data/pry-0.16.0/lib/pry/testable.rb +68 -0
  137. data/pry-0.16.0/lib/pry/version.rb +5 -0
  138. data/pry-0.16.0/lib/pry/warning.rb +20 -0
  139. data/pry-0.16.0/lib/pry/wrapped_module/candidate.rb +145 -0
  140. data/pry-0.16.0/lib/pry/wrapped_module.rb +382 -0
  141. data/pry-0.16.0/lib/pry.rb +148 -0
  142. data/super-smart-mod.gemspec +12 -0
  143. metadata +182 -0
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Method
5
+ class Patcher
6
+ attr_accessor :method
7
+
8
+ # rubocop:disable Style/ClassVars
9
+ @@source_cache = {}
10
+ # rubocop:enable Style/ClassVars
11
+
12
+ def initialize(method)
13
+ @method = method
14
+ end
15
+
16
+ def self.code_for(filename)
17
+ @@source_cache[filename]
18
+ end
19
+
20
+ # perform the patch
21
+ def patch_in_ram(source)
22
+ if method.alias?
23
+ with_method_transaction do
24
+ redefine source
25
+ end
26
+ else
27
+ redefine source
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def redefine(source)
34
+ @@source_cache[cache_key] = source
35
+ TOPLEVEL_BINDING.eval wrap(source), cache_key
36
+ end
37
+
38
+ def cache_key
39
+ "pry-redefined(0x#{method.owner.object_id.to_s(16)}##{method.name})"
40
+ end
41
+
42
+ # Run some code ensuring that at the end target#meth_name will not have changed.
43
+ #
44
+ # When we're redefining aliased methods we will overwrite the method at the
45
+ # unaliased name (so that super continues to work). By wrapping that code in a
46
+ # translation we make that not happen, which means that alias_method_chains, etc.
47
+ # continue to work.
48
+ #
49
+ def with_method_transaction
50
+ temp_name = "__pry_#{method.original_name}__"
51
+ method = self.method
52
+ method.owner.class_eval do
53
+ alias_method temp_name, method.original_name
54
+ yield
55
+ alias_method method.name, method.original_name
56
+ alias_method method.original_name, temp_name
57
+ end
58
+ ensure
59
+ begin
60
+ method.send(:remove_method, temp_name)
61
+ rescue StandardError
62
+ nil
63
+ end
64
+ end
65
+
66
+ # Update the definition line so that it can be eval'd directly on the Method's
67
+ # owner instead of from the original context.
68
+ #
69
+ # In particular this takes `def self.foo` and turns it into `def foo` so that we
70
+ # don't end up creating the method on the singleton class of the singleton class
71
+ # by accident.
72
+ #
73
+ # This is necessarily done by String manipulation because we can't find out what
74
+ # syntax is needed for the argument list by ruby-level introspection.
75
+ #
76
+ # @param [String] line The original definition line. e.g. def self.foo(bar, baz=1)
77
+ # @return [String] The new definition line. e.g. def foo(bar, baz=1)
78
+ def definition_for_owner(line)
79
+ if line =~ /\Adef (?:.*?\.)?#{Regexp.escape(method.original_name)}(?=[\(\s;]|$)/
80
+ "def #{method.original_name}#{$'}"
81
+ else
82
+ raise CommandError,
83
+ "Could not find original `def #{method.original_name}` line " \
84
+ "to patch."
85
+ end
86
+ end
87
+
88
+ # Apply wrap_for_owner and wrap_for_nesting successively to `source`
89
+ # @param [String] source
90
+ # @return [String] The wrapped source.
91
+ def wrap(source)
92
+ wrap_for_nesting(wrap_for_owner(source))
93
+ end
94
+
95
+ # Update the source code so that when it has the right owner when eval'd.
96
+ #
97
+ # This (combined with definition_for_owner) is backup for the case that
98
+ # wrap_for_nesting fails, to ensure that the method will still be defined in
99
+ # the correct place.
100
+ #
101
+ # @param [String] source The source to wrap
102
+ # @return [String]
103
+ def wrap_for_owner(source)
104
+ Pry.current[:pry_owner] = method.owner
105
+ owner_source = definition_for_owner(source)
106
+ visibility_fix = "#{method.visibility} #{method.name.to_sym.inspect}"
107
+ "Pry.current[:pry_owner].class_eval do; #{owner_source}\n#{visibility_fix}\nend"
108
+ end
109
+
110
+ # Update the new source code to have the correct Module.nesting.
111
+ #
112
+ # This method uses syntactic analysis of the original source file to determine
113
+ # the new nesting, so that we can tell the difference between:
114
+ #
115
+ # class A; def self.b; end; end
116
+ # class << A; def b; end; end
117
+ #
118
+ # The resulting code should be evaluated in the TOPLEVEL_BINDING.
119
+ #
120
+ # @param [String] source The source to wrap.
121
+ # @return [String]
122
+ def wrap_for_nesting(source)
123
+ nesting = Pry::Code.from_file(method.source_file).nesting_at(method.source_line)
124
+
125
+ (nesting + [source] + nesting.map { "end" } + [""]).join(";")
126
+ rescue Pry::Indent::UnparseableNestingError
127
+ source
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,222 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Method
5
+ # This class is responsible for locating the *real* `Pry::Method`
6
+ # object captured by a binding.
7
+ #
8
+ # Given a `Binding` from inside a method and a 'seed' Pry::Method object,
9
+ # there are primarily two situations where the seed method doesn't match
10
+ # the Binding:
11
+ # 1. The Pry::Method is from a subclass
12
+ # 2. The Pry::Method represents a method of the same name while the original
13
+ # was renamed to something else. For 1. we search vertically up the
14
+ # inheritance chain, and for 2. we search laterally along the object's
15
+ # method table.
16
+ #
17
+ # When we locate the method that matches the Binding we wrap it in
18
+ # Pry::Method and return it, or return nil if we fail.
19
+ class WeirdMethodLocator
20
+ class << self
21
+ # Whether the given method object matches the associated binding.
22
+ # If the method object does not match the binding, then it's
23
+ # most likely not the method captured by the binding, and we
24
+ # must commence a search.
25
+ #
26
+ # @param [Pry::Method] method
27
+ # @param [Binding] binding
28
+ # @return [Boolean]
29
+ def normal_method?(method, binding)
30
+ if method && method.source_file && method.source_range
31
+ if binding.respond_to?(:source_location)
32
+ binding_file, binding_line = binding.source_location
33
+ else
34
+ binding_file = binding.eval('__FILE__')
35
+ binding_line = binding.eval('__LINE__')
36
+ end
37
+ (File.expand_path(method.source_file) == File.expand_path(binding_file)) &&
38
+ method.source_range.include?(binding_line)
39
+ end
40
+ rescue StandardError
41
+ false
42
+ end
43
+
44
+ def weird_method?(method, binding)
45
+ !normal_method?(method, binding)
46
+ end
47
+ end
48
+
49
+ attr_accessor :method
50
+ attr_accessor :target
51
+
52
+ # @param [Pry::Method] method The seed method.
53
+ # @param [Binding] target The Binding that captures the method
54
+ # we want to locate.
55
+ def initialize(method, target)
56
+ @method = method
57
+ @target = target
58
+ end
59
+
60
+ # @return [Pry::Method, nil] The Pry::Method that matches the
61
+ # given binding.
62
+ def find_method
63
+ find_renamed_method || find_method_in_superclass
64
+ end
65
+
66
+ # @return [Boolean] Whether the Pry::Method is unrecoverable
67
+ # This usually happens when the method captured by the Binding
68
+ # has been subsequently deleted.
69
+ def lost_method?
70
+ !!(find_method.nil? && renamed_method_source_location)
71
+ end
72
+
73
+ private
74
+
75
+ def skip_superclass_search?
76
+ target_mod = @target.eval('self').class
77
+ target_mod.ancestors.take_while { |mod| mod != target_mod }.any?
78
+ end
79
+
80
+ def normal_method?(method)
81
+ self.class.normal_method?(method, target)
82
+ end
83
+
84
+ def target_self
85
+ target.eval('self')
86
+ end
87
+
88
+ def target_file
89
+ file =
90
+ if target.respond_to?(:source_location)
91
+ target.source_location.first
92
+ else
93
+ target.eval('__FILE__')
94
+ end
95
+ pry_file? ? file : File.expand_path(file)
96
+ end
97
+
98
+ def target_line
99
+ if target.respond_to?(:source_location)
100
+ target.source_location[1]
101
+ else
102
+ target.eval('__LINE__')
103
+ end
104
+ end
105
+
106
+ def pry_file?
107
+ file =
108
+ if target.respond_to?(:source_location)
109
+ target.source_location.first
110
+ else
111
+ target.eval('__FILE__')
112
+ end
113
+ Pry.eval_path == file
114
+ end
115
+
116
+ # it's possible in some cases that the method we find by this approach is
117
+ # a sub-method of the one we're currently in, consider:
118
+ #
119
+ # class A; def b; binding.pry; end; end
120
+ # class B < A; def b; super; end; end
121
+ #
122
+ # Given that we can normally find the source_range of methods, and that we
123
+ # know which __FILE__ and __LINE__ the binding is at, we can hope to
124
+ # disambiguate these cases.
125
+ #
126
+ # This obviously won't work if the source is unavailable for some reason,
127
+ # or if both methods have the same __FILE__ and __LINE__.
128
+ #
129
+ # @return [Pry::Method, nil] The Pry::Method representing the
130
+ # superclass method.
131
+ def find_method_in_superclass
132
+ guess = method
133
+ return guess if skip_superclass_search?
134
+
135
+ while guess
136
+ # needs rescue if this is a Disowned method or a C method or something...
137
+ # TODO: Fix up the exception handling so we don't need a bare rescue
138
+ return guess if normal_method?(guess)
139
+ break if guess == guess.super
140
+
141
+ guess = guess.super
142
+ end
143
+
144
+ # Uhoh... none of the methods in the chain had the right `__FILE__` and
145
+ # `__LINE__` due to unknown circumstances.
146
+ # TODO: we should warn the user when this happens.
147
+ nil
148
+ end
149
+
150
+ # This is the case where the name of a method has changed
151
+ # (via alias_method) so we locate the Method object for the
152
+ # renamed method.
153
+ #
154
+ # @return [Pry::Method, nil] The Pry::Method representing the
155
+ # renamed method
156
+ def find_renamed_method
157
+ return unless valid_file?(target_file)
158
+
159
+ alias_name = all_methods_for(target_self).find do |v|
160
+ location = target_self.method(v).source_location
161
+ location && expanded_source_location(location) == renamed_method_source_location
162
+ end
163
+
164
+ alias_name && Pry::Method(target_self.method(alias_name))
165
+ end
166
+
167
+ def expanded_source_location(source_location)
168
+ return unless source_location
169
+
170
+ if pry_file?
171
+ source_location
172
+ else
173
+ [File.expand_path(source_location.first), source_location[1]]
174
+ end
175
+ end
176
+
177
+ # Use static analysis to locate the start of the method definition.
178
+ # We have the `__FILE__` and `__LINE__` from the binding and the
179
+ # original name of the method so we search up until we find a
180
+ # def/define_method, etc defining a method of the appropriate name.
181
+ #
182
+ # @return [Array<String, Fixnum>] The `source_location` of the
183
+ # renamed method
184
+ def renamed_method_source_location
185
+ if defined?(@original_method_source_location)
186
+ return @original_method_source_location
187
+ end
188
+
189
+ source_index = lines_for_file(target_file)[0..(target_line - 1)].rindex do |v|
190
+ Pry::Method.method_definition?(method.name, v)
191
+ end
192
+
193
+ @original_method_source_location =
194
+ source_index && [target_file, index_to_line_number(source_index)]
195
+ end
196
+
197
+ def index_to_line_number(index)
198
+ # Pry.line_buffer is 0-indexed
199
+ pry_file? ? index : index + 1
200
+ end
201
+
202
+ def valid_file?(file)
203
+ (File.exist?(file) && !File.directory?(file)) || Pry.eval_path == file
204
+ end
205
+
206
+ def lines_for_file(file)
207
+ @lines_for_file ||= {}
208
+ @lines_for_file[file] ||= if Pry.eval_path == file
209
+ Pry.line_buffer
210
+ else
211
+ File.readlines(file)
212
+ end
213
+ end
214
+
215
+ def all_methods_for(obj)
216
+ obj.public_methods(false) +
217
+ obj.private_methods(false) +
218
+ obj.protected_methods(false)
219
+ end
220
+ end
221
+ end
222
+ end