pry 0.9.10pre1-i386-mingw32 → 0.9.11-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. data/.travis.yml +3 -1
  2. data/CHANGELOG +63 -2
  3. data/CONTRIBUTORS +43 -25
  4. data/Gemfile +7 -0
  5. data/Guardfile +62 -0
  6. data/README.markdown +4 -4
  7. data/Rakefile +34 -35
  8. data/lib/pry.rb +107 -54
  9. data/lib/pry/cli.rb +34 -11
  10. data/lib/pry/code.rb +165 -182
  11. data/lib/pry/code/code_range.rb +70 -0
  12. data/lib/pry/code/loc.rb +92 -0
  13. data/lib/pry/code_object.rb +153 -0
  14. data/lib/pry/command.rb +160 -22
  15. data/lib/pry/command_set.rb +37 -26
  16. data/lib/pry/commands.rb +4 -27
  17. data/lib/pry/commands/amend_line.rb +99 -0
  18. data/lib/pry/commands/bang.rb +20 -0
  19. data/lib/pry/commands/bang_pry.rb +17 -0
  20. data/lib/pry/commands/cat.rb +53 -0
  21. data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  22. data/lib/pry/commands/cat/exception_formatter.rb +78 -0
  23. data/lib/pry/commands/cat/file_formatter.rb +84 -0
  24. data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  25. data/lib/pry/commands/cd.rb +30 -0
  26. data/lib/pry/commands/code_collector.rb +165 -0
  27. data/lib/pry/commands/deprecated_commands.rb +2 -0
  28. data/lib/pry/commands/disable_pry.rb +27 -0
  29. data/lib/pry/commands/easter_eggs.rb +112 -0
  30. data/lib/pry/commands/edit.rb +206 -0
  31. data/lib/pry/commands/edit/exception_patcher.rb +25 -0
  32. data/lib/pry/commands/edit/file_and_line_locator.rb +38 -0
  33. data/lib/pry/commands/edit/method_patcher.rb +122 -0
  34. data/lib/pry/commands/exit.rb +42 -0
  35. data/lib/pry/commands/exit_all.rb +29 -0
  36. data/lib/pry/commands/exit_program.rb +24 -0
  37. data/lib/pry/commands/find_method.rb +199 -0
  38. data/lib/pry/commands/fix_indent.rb +19 -0
  39. data/lib/pry/commands/gem_cd.rb +26 -0
  40. data/lib/pry/commands/gem_install.rb +29 -0
  41. data/lib/pry/commands/gem_list.rb +33 -0
  42. data/lib/pry/commands/gem_open.rb +29 -0
  43. data/lib/pry/commands/gist.rb +95 -0
  44. data/lib/pry/commands/help.rb +164 -0
  45. data/lib/pry/commands/hist.rb +161 -0
  46. data/lib/pry/commands/import_set.rb +22 -0
  47. data/lib/pry/commands/install_command.rb +51 -0
  48. data/lib/pry/commands/jump_to.rb +29 -0
  49. data/lib/pry/commands/ls.rb +339 -0
  50. data/lib/pry/commands/nesting.rb +25 -0
  51. data/lib/pry/commands/play.rb +69 -0
  52. data/lib/pry/commands/pry_backtrace.rb +26 -0
  53. data/lib/pry/commands/pry_version.rb +17 -0
  54. data/lib/pry/commands/raise_up.rb +32 -0
  55. data/lib/pry/commands/reload_code.rb +39 -0
  56. data/lib/pry/commands/reset.rb +18 -0
  57. data/lib/pry/commands/ri.rb +56 -0
  58. data/lib/pry/commands/save_file.rb +61 -0
  59. data/lib/pry/commands/shell_command.rb +43 -0
  60. data/lib/pry/commands/shell_mode.rb +27 -0
  61. data/lib/pry/commands/show_doc.rb +78 -0
  62. data/lib/pry/commands/show_info.rb +139 -0
  63. data/lib/pry/commands/show_input.rb +17 -0
  64. data/lib/pry/commands/show_source.rb +37 -0
  65. data/lib/pry/commands/simple_prompt.rb +22 -0
  66. data/lib/pry/commands/stat.rb +40 -0
  67. data/lib/pry/commands/switch_to.rb +23 -0
  68. data/lib/pry/commands/toggle_color.rb +20 -0
  69. data/lib/pry/commands/whereami.rb +114 -0
  70. data/lib/pry/commands/wtf.rb +57 -0
  71. data/lib/pry/completion.rb +120 -46
  72. data/lib/pry/config.rb +11 -0
  73. data/lib/pry/core_extensions.rb +30 -19
  74. data/lib/pry/editor.rb +129 -0
  75. data/lib/pry/helpers.rb +1 -0
  76. data/lib/pry/helpers/base_helpers.rb +89 -119
  77. data/lib/pry/helpers/command_helpers.rb +7 -122
  78. data/lib/pry/helpers/table.rb +100 -0
  79. data/lib/pry/helpers/text.rb +4 -4
  80. data/lib/pry/history_array.rb +5 -0
  81. data/lib/pry/hooks.rb +1 -3
  82. data/lib/pry/indent.rb +104 -30
  83. data/lib/pry/method.rb +66 -22
  84. data/lib/pry/module_candidate.rb +26 -15
  85. data/lib/pry/pager.rb +70 -0
  86. data/lib/pry/plugins.rb +1 -2
  87. data/lib/pry/pry_class.rb +63 -22
  88. data/lib/pry/pry_instance.rb +58 -37
  89. data/lib/pry/rubygem.rb +74 -0
  90. data/lib/pry/terminal_info.rb +43 -0
  91. data/lib/pry/test/helper.rb +185 -0
  92. data/lib/pry/version.rb +1 -1
  93. data/lib/pry/wrapped_module.rb +58 -24
  94. data/pry.gemspec +21 -37
  95. data/{test/test_cli.rb → spec/cli_spec.rb} +0 -0
  96. data/spec/code_object_spec.rb +277 -0
  97. data/{test/test_code.rb → spec/code_spec.rb} +19 -1
  98. data/{test/test_command_helpers.rb → spec/command_helpers_spec.rb} +0 -0
  99. data/{test/test_command_integration.rb → spec/command_integration_spec.rb} +38 -46
  100. data/{test/test_command_set.rb → spec/command_set_spec.rb} +18 -1
  101. data/{test/test_command.rb → spec/command_spec.rb} +250 -149
  102. data/spec/commands/amend_line_spec.rb +247 -0
  103. data/spec/commands/bang_spec.rb +19 -0
  104. data/spec/commands/cat_spec.rb +164 -0
  105. data/spec/commands/cd_spec.rb +250 -0
  106. data/spec/commands/disable_pry_spec.rb +25 -0
  107. data/spec/commands/edit_spec.rb +727 -0
  108. data/spec/commands/exit_all_spec.rb +34 -0
  109. data/spec/commands/exit_program_spec.rb +19 -0
  110. data/spec/commands/exit_spec.rb +34 -0
  111. data/{test/test_default_commands/test_find_method.rb → spec/commands/find_method_spec.rb} +27 -7
  112. data/spec/commands/gem_list_spec.rb +26 -0
  113. data/spec/commands/gist_spec.rb +75 -0
  114. data/{test/test_default_commands/test_help.rb → spec/commands/help_spec.rb} +8 -9
  115. data/spec/commands/hist_spec.rb +181 -0
  116. data/spec/commands/jump_to_spec.rb +15 -0
  117. data/spec/commands/ls_spec.rb +177 -0
  118. data/spec/commands/play_spec.rb +140 -0
  119. data/spec/commands/raise_up_spec.rb +56 -0
  120. data/spec/commands/save_file_spec.rb +177 -0
  121. data/spec/commands/show_doc_spec.rb +378 -0
  122. data/spec/commands/show_input_spec.rb +17 -0
  123. data/spec/commands/show_source_spec.rb +597 -0
  124. data/spec/commands/whereami_spec.rb +154 -0
  125. data/spec/completion_spec.rb +233 -0
  126. data/spec/control_d_handler_spec.rb +58 -0
  127. data/spec/editor_spec.rb +79 -0
  128. data/{test/test_exception_whitelist.rb → spec/exception_whitelist_spec.rb} +0 -0
  129. data/{test → spec/fixtures}/candidate_helper1.rb +0 -0
  130. data/{test → spec/fixtures}/candidate_helper2.rb +0 -0
  131. data/{test/test_default_commands → spec/fixtures}/example.erb +0 -0
  132. data/spec/fixtures/example_nesting.rb +33 -0
  133. data/spec/fixtures/show_source_doc_examples.rb +15 -0
  134. data/{test → spec/fixtures}/testrc +0 -0
  135. data/{test → spec/fixtures}/testrcbad +0 -0
  136. data/spec/helper.rb +34 -0
  137. data/spec/helpers/bacon.rb +86 -0
  138. data/spec/helpers/mock_pry.rb +43 -0
  139. data/spec/helpers/table_spec.rb +83 -0
  140. data/{test/test_history_array.rb → spec/history_array_spec.rb} +21 -19
  141. data/{test/test_hooks.rb → spec/hooks_spec.rb} +0 -0
  142. data/{test/test_indent.rb → spec/indent_spec.rb} +24 -0
  143. data/{test/test_input_stack.rb → spec/input_stack_spec.rb} +4 -0
  144. data/{test/test_method.rb → spec/method_spec.rb} +65 -1
  145. data/{test/test_prompt.rb → spec/prompt_spec.rb} +0 -0
  146. data/{test/test_pry_defaults.rb → spec/pry_defaults_spec.rb} +14 -14
  147. data/{test/test_pry_history.rb → spec/pry_history_spec.rb} +15 -0
  148. data/spec/pry_output_spec.rb +95 -0
  149. data/{test/test_pry.rb → spec/pry_spec.rb} +74 -32
  150. data/{test/test_sticky_locals.rb → spec/sticky_locals_spec.rb} +27 -25
  151. data/{test/test_syntax_checking.rb → spec/syntax_checking_spec.rb} +17 -1
  152. data/{test/test_wrapped_module.rb → spec/wrapped_module_spec.rb} +92 -5
  153. metadata +239 -115
  154. data/examples/example_basic.rb +0 -15
  155. data/examples/example_command_override.rb +0 -32
  156. data/examples/example_commands.rb +0 -36
  157. data/examples/example_hooks.rb +0 -9
  158. data/examples/example_image_edit.rb +0 -67
  159. data/examples/example_input.rb +0 -7
  160. data/examples/example_input2.rb +0 -29
  161. data/examples/example_output.rb +0 -11
  162. data/examples/example_print.rb +0 -6
  163. data/examples/example_prompt.rb +0 -9
  164. data/examples/helper.rb +0 -6
  165. data/lib/pry/default_commands/cd.rb +0 -81
  166. data/lib/pry/default_commands/commands.rb +0 -62
  167. data/lib/pry/default_commands/context.rb +0 -98
  168. data/lib/pry/default_commands/easter_eggs.rb +0 -95
  169. data/lib/pry/default_commands/editing.rb +0 -420
  170. data/lib/pry/default_commands/find_method.rb +0 -169
  171. data/lib/pry/default_commands/gems.rb +0 -84
  172. data/lib/pry/default_commands/gist.rb +0 -187
  173. data/lib/pry/default_commands/help.rb +0 -127
  174. data/lib/pry/default_commands/hist.rb +0 -120
  175. data/lib/pry/default_commands/input_and_output.rb +0 -306
  176. data/lib/pry/default_commands/introspection.rb +0 -410
  177. data/lib/pry/default_commands/ls.rb +0 -272
  178. data/lib/pry/default_commands/misc.rb +0 -38
  179. data/lib/pry/default_commands/navigating_pry.rb +0 -110
  180. data/lib/pry/default_commands/whereami.rb +0 -92
  181. data/lib/pry/extended_commands/experimental.rb +0 -7
  182. data/test/helper.rb +0 -223
  183. data/test/test_completion.rb +0 -62
  184. data/test/test_control_d_handler.rb +0 -45
  185. data/test/test_default_commands/test_cd.rb +0 -321
  186. data/test/test_default_commands/test_context.rb +0 -288
  187. data/test/test_default_commands/test_documentation.rb +0 -315
  188. data/test/test_default_commands/test_gems.rb +0 -18
  189. data/test/test_default_commands/test_input.rb +0 -428
  190. data/test/test_default_commands/test_introspection.rb +0 -511
  191. data/test/test_default_commands/test_ls.rb +0 -151
  192. data/test/test_default_commands/test_shell.rb +0 -343
  193. data/test/test_default_commands/test_show_source.rb +0 -432
  194. data/test/test_pry_output.rb +0 -41
@@ -0,0 +1,74 @@
1
+ require 'rubygems'
2
+
3
+ class Pry
4
+ module Rubygem
5
+
6
+ class << self
7
+ def installed?(name)
8
+ if Gem::Specification.respond_to?(:find_all_by_name)
9
+ Gem::Specification.find_all_by_name(name).any?
10
+ else
11
+ Gem.source_index.find_name(name).first
12
+ end
13
+ end
14
+
15
+ # Get the gem spec object for the given gem name.
16
+ #
17
+ # @param [String] name
18
+ # @return [Gem::Specification]
19
+ def spec(name)
20
+ specs = if Gem::Specification.respond_to?(:each)
21
+ Gem::Specification.find_all_by_name(name)
22
+ else
23
+ Gem.source_index.find_name(name)
24
+ end
25
+
26
+ spec = specs.sort_by{ |spec| Gem::Version.new(spec.version) }.first
27
+
28
+ spec or raise CommandError, "Gem `#{name}` not found"
29
+ end
30
+
31
+ # List gems matching a pattern.
32
+ #
33
+ # @param [Regexp] pattern
34
+ # @return [Array<Gem::Specification>]
35
+ def list(pattern = /.*/)
36
+ if Gem::Specification.respond_to?(:each)
37
+ Gem::Specification.select{|spec| spec.name =~ pattern }
38
+ else
39
+ Gem.source_index.gems.values.select{|spec| spec.name =~ pattern }
40
+ end
41
+ end
42
+
43
+ # Completion function for gem-cd and gem-open.
44
+ #
45
+ # @param [String] so_far what the user's typed so far
46
+ # @return [Array<String>] completions
47
+ def complete(so_far)
48
+ if so_far =~ / ([^ ]*)\z/
49
+ self.list(%r{\A#{$2}}).map(&:name)
50
+ else
51
+ self.list.map(&:name)
52
+ end
53
+ end
54
+
55
+ # Installs a gem with all its dependencies.
56
+ #
57
+ # @param [String] name
58
+ # @return [void]
59
+ def install(name)
60
+ destination = File.writable?(Gem.dir) ? Gem.dir : Gem.user_dir
61
+ installer = Gem::DependencyInstaller.new(:install_dir => destination)
62
+ installer.install(name)
63
+ rescue Errno::EACCES
64
+ raise CommandError,
65
+ "Insufficient permissions to install `#{ text.green(name) }`."
66
+ rescue Gem::GemNotFoundException
67
+ raise CommandError, "Gem `#{ text.green(name) }` not found."
68
+ else
69
+ Gem.refresh
70
+ end
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,43 @@
1
+ class Pry::TerminalInfo
2
+ # Return a pair of [rows, columns] which gives the size of the window.
3
+ #
4
+ # If the window size cannot be determined, return nil.
5
+ def self.screen_size
6
+ rows, cols = actual_screen_size
7
+ if rows && cols
8
+ [rows.to_i, cols.to_i]
9
+ else
10
+ nil
11
+ end
12
+ end
13
+
14
+ def self.actual_screen_size
15
+ [
16
+ # Some readlines also provides get_screen_size.
17
+ # Readline comes before IO#winsize because jruby sometimes defaults winsize to [25, 80]
18
+ readline_screen_size,
19
+
20
+ # io/console adds a winsize method to IO streams.
21
+ # rescue nil for jruby 1.7.0 [jruby/jruby#354]
22
+ $stdout.tty? && $stdout.respond_to?(:winsize) && ($stdout.winsize rescue nil),
23
+
24
+ # Otherwise try to use the environment (this may be out of date due
25
+ # to window resizing, but it's better than nothing).
26
+ [ENV["LINES"] || ENV["ROWS"], ENV["COLUMNS"]],
27
+
28
+ # If the user is running within ansicon, then use the screen size
29
+ # that it reports (same caveats apply as with ROWS and COLUMNS)
30
+ ENV['ANSICON'] =~ /\((.*)x(.*)\)/ && [$2, $1],
31
+ ].detect do |(_, cols)|
32
+ cols.to_i > 0
33
+ end
34
+ end
35
+
36
+ def self.readline_screen_size
37
+ Readline.get_screen_size if Readline.respond_to?(:get_screen_size)
38
+ rescue Java::JavaLang::NullPointerException
39
+ # This rescue won't happen on jrubies later than:
40
+ # https://github.com/jruby/jruby/pull/436
41
+ nil
42
+ end
43
+ end
@@ -0,0 +1,185 @@
1
+ require 'pry'
2
+
3
+ # in case the tests call reset_defaults, ensure we reset them to
4
+ # amended (test friendly) values
5
+ class << Pry
6
+ alias_method :orig_reset_defaults, :reset_defaults
7
+ def reset_defaults
8
+ orig_reset_defaults
9
+
10
+ Pry.color = false
11
+ Pry.pager = false
12
+ Pry.config.should_load_rc = false
13
+ Pry.config.should_load_local_rc= false
14
+ Pry.config.should_load_plugins = false
15
+ Pry.config.history.should_load = false
16
+ Pry.config.history.should_save = false
17
+ Pry.config.auto_indent = false
18
+ Pry.config.hooks = Pry::Hooks.new
19
+ Pry.config.collision_warning = false
20
+ end
21
+ end
22
+ Pry.reset_defaults
23
+
24
+ # A global space for storing temporary state during tests.
25
+
26
+ module PryTestHelpers
27
+
28
+ module_function
29
+
30
+ # inject a variable into a binding
31
+ def inject_var(name, value, b)
32
+ Pry.current[:pry_local] = value
33
+ b.eval("#{name} = ::Pry.current[:pry_local]")
34
+ ensure
35
+ Pry.current[:pry_local] = nil
36
+ end
37
+
38
+ def constant_scope(*names)
39
+ names.each do |name|
40
+ Object.remove_const name if Object.const_defined?(name)
41
+ end
42
+
43
+ yield
44
+ ensure
45
+ names.each do |name|
46
+ Object.remove_const name if Object.const_defined?(name)
47
+ end
48
+ end
49
+
50
+ def mri18_and_no_real_source_location?
51
+ Pry::Helpers::BaseHelpers.mri_18? && !(Method.instance_method(:source_location).owner == Method)
52
+ end
53
+
54
+ # Open a temp file and yield it to the block, closing it after
55
+ # @return [String] The path of the temp file
56
+ def temp_file(ext='.rb')
57
+ file = Tempfile.new(['pry', ext])
58
+ yield file
59
+ ensure
60
+ file.close(true) if file
61
+ File.unlink("#{file.path}c") if File.exists?("#{file.path}c") # rbx
62
+ end
63
+
64
+ def unindent(*args)
65
+ Pry::Helpers::CommandHelpers.unindent(*args)
66
+ end
67
+
68
+ def mock_command(cmd, args=[], opts={})
69
+ output = StringIO.new
70
+ ret = cmd.new(opts.merge(:output => output)).call_safely(*args)
71
+ Struct.new(:output, :return).new(output.string, ret)
72
+ end
73
+
74
+ def mock_exception(*mock_backtrace)
75
+ e = StandardError.new("mock exception")
76
+ (class << e; self; end).class_eval do
77
+ define_method(:backtrace) { mock_backtrace }
78
+ end
79
+ e
80
+ end
81
+ end
82
+
83
+ def pry_tester(*args, &block)
84
+ if args.length == 0 || args[0].is_a?(Hash)
85
+ args.unshift(Pry.toplevel_binding)
86
+ end
87
+
88
+ PryTester.new(*args).tap do |t|
89
+ (class << t; self; end).class_eval(&block) if block
90
+ end
91
+ end
92
+
93
+ def pry_eval(*eval_strs)
94
+ if eval_strs.first.is_a? String
95
+ binding = Pry.toplevel_binding
96
+ else
97
+ binding = Pry.binding_for(eval_strs.shift)
98
+ end
99
+
100
+ pry_tester(binding).eval(*eval_strs)
101
+ end
102
+
103
+ class PryTester
104
+ attr_reader :pry, :out
105
+
106
+ def initialize(context = TOPLEVEL_BINDING, options = {})
107
+ @pry = Pry.new(options)
108
+
109
+ if context
110
+ target = Pry.binding_for(context)
111
+ @pry.binding_stack << target
112
+ @pry.inject_sticky_locals(target)
113
+ end
114
+
115
+ @pry.input_array << nil # TODO: shouldn't need this
116
+ reset_output
117
+ end
118
+
119
+ def eval(*strs)
120
+ reset_output
121
+ result = nil
122
+
123
+ strs.flatten.each do |str|
124
+ str = "#{str.strip}\n"
125
+ if @pry.process_command(str)
126
+ result = last_command_result_or_output
127
+ else
128
+ result = @pry.evaluate_ruby(str)
129
+ end
130
+ end
131
+
132
+ result
133
+ end
134
+
135
+ def context=(context)
136
+ @pry.binding_stack << Pry.binding_for(context)
137
+ end
138
+
139
+ # TODO: eliminate duplication with Pry#repl
140
+ def simulate_repl
141
+ didnt_exit = nil
142
+ break_data = nil
143
+
144
+ didnt_exit = catch(:didnt_exit) do
145
+ break_data = catch(:breakout) do
146
+ yield self
147
+ throw(:didnt_exit, true)
148
+ end
149
+ nil
150
+ end
151
+
152
+ raise "Failed to exit REPL" if didnt_exit
153
+ break_data
154
+ end
155
+
156
+ def last_output
157
+ @out.string if @out
158
+ end
159
+
160
+ def process_command(command_str, eval_str = '')
161
+ @pry.process_command(command_str, eval_str) or raise "Not a valid command"
162
+ last_command_result_or_output
163
+ end
164
+
165
+ protected
166
+
167
+ def last_command_result
168
+ result = Pry.current[:pry_cmd_result]
169
+ result.retval if result
170
+ end
171
+
172
+ def last_command_result_or_output
173
+ result = last_command_result
174
+ if result != Pry::Command::VOID_VALUE
175
+ result
176
+ else
177
+ last_output
178
+ end
179
+ end
180
+
181
+ def reset_output
182
+ @out = StringIO.new
183
+ @pry.output = @out
184
+ end
185
+ end
@@ -1,3 +1,3 @@
1
1
  class Pry
2
- VERSION = "0.9.10pre1"
2
+ VERSION = "0.9.11"
3
3
  end
@@ -14,10 +14,10 @@ class Pry
14
14
  end
15
15
 
16
16
  class WrappedModule
17
- include Pry::Helpers::DocumentationHelpers
17
+ include Helpers::BaseHelpers
18
+ include CodeObject::Helpers
18
19
 
19
20
  attr_reader :wrapped
20
- private :wrapped
21
21
 
22
22
  # Convert a string to a module.
23
23
  #
@@ -27,11 +27,7 @@ class Pry
27
27
  # @example
28
28
  # Pry::WrappedModule.from_str("Pry::Code")
29
29
  def self.from_str(mod_name, target=TOPLEVEL_BINDING)
30
- kind = target.eval("defined?(#{mod_name})")
31
-
32
- # if we dont limit it to constants then from_str could end up
33
- # executing methods which is not good, i.e `show-source pry`
34
- if (kind == "constant" && target.eval(mod_name).is_a?(Module))
30
+ if safe_to_evaluate?(mod_name, target)
35
31
  Pry::WrappedModule.new(target.eval(mod_name))
36
32
  else
37
33
  nil
@@ -40,6 +36,23 @@ class Pry
40
36
  nil
41
37
  end
42
38
 
39
+ class << self
40
+ private
41
+
42
+ # We use this method to decide whether code is safe to eval. Method's are
43
+ # generally not, but everything else is.
44
+ # TODO: is just checking != "method" enough??
45
+ # TODO: see duplication of this method in Pry::CodeObject
46
+ # @param [String] str The string to lookup.
47
+ # @param [Binding] target Where the lookup takes place.
48
+ # @return [Boolean]
49
+ def safe_to_evaluate?(str, target)
50
+ return true if str.strip == "self"
51
+ kind = target.eval("defined?(#{str})")
52
+ kind =~ /variable|constant/
53
+ end
54
+ end
55
+
43
56
  # @raise [ArgumentError] if the argument is not a `Module`
44
57
  # @param [Module] mod
45
58
  def initialize(mod)
@@ -204,6 +217,24 @@ class Pry
204
217
  !!(defined?(YARD) && YARD::Registry.at(name))
205
218
  end
206
219
 
220
+ # @param [Fixnum] times How far to travel up the ancestor chain.
221
+ # @return [Pry::WrappedModule, nil] The wrapped module that is the
222
+ # superclass.
223
+ # When `self` is a `Module` then return the
224
+ # nth ancestor, otherwise (in the case of classes) return the
225
+ # nth ancestor that is a class.
226
+ def super(times=1)
227
+ return self if times.zero?
228
+
229
+ if wrapped.is_a?(Class)
230
+ sup = ancestors.select { |v| v.is_a?(Class) }[times]
231
+ else
232
+ sup = ancestors[times]
233
+ end
234
+
235
+ Pry::WrappedModule(sup) if sup
236
+ end
237
+
207
238
  private
208
239
 
209
240
  # @return [Pry::WrappedModule::Candidate] The candidate of rank 0,
@@ -231,17 +262,23 @@ class Pry
231
262
  def all_source_locations_by_popularity
232
263
  return @all_source_locations_by_popularity if @all_source_locations_by_popularity
233
264
 
234
- ims = all_methods_for(wrapped)
235
-
236
- # reject __class_init__ because it's an odd rbx specific thing that causes tests to fail
237
- ims = ims.select(&:source_location).reject{ |x| x.name == '__class_init__' }
238
-
265
+ ims = all_relevant_methods_for(wrapped)
239
266
  @all_source_locations_by_popularity = ims.group_by { |v| Array(v.source_location).first }.
240
267
  sort_by { |k, v| -v.size }
241
268
  end
242
269
 
270
+ # We only want methods that have a non-nil `source_location`. We also
271
+ # skip some spooky internal methods.
272
+ # (i.e we skip `__class_init__` because it's an odd rbx specific thing that causes tests to fail.)
273
+ # @return [Array<Pry::Method>]
274
+ def all_relevant_methods_for(mod)
275
+ all_methods_for(mod).select(&:source_location).
276
+ reject{ |x| x.name == '__class_init__' || method_defined_by_forwardable_module?(x) }
277
+ end
278
+
243
279
  # Return all methods (instance methods and class methods) for a
244
280
  # given module.
281
+ # @return [Array<Pry::Method>]
245
282
  def all_methods_for(mod)
246
283
  all_from_common(mod, :instance_method) + all_from_common(mod, :method)
247
284
  end
@@ -261,6 +298,15 @@ class Pry
261
298
  end.flatten
262
299
  end
263
300
 
301
+ # Detect methods that are defined with `def_delegator` from the Forwardable
302
+ # module. We want to reject these methods as they screw up module
303
+ # extraction since the `source_location` for such methods points at forwardable.rb
304
+ # TODO: make this more robust as valid user-defined files called
305
+ # forwardable.rb are also skipped.
306
+ def method_defined_by_forwardable_module?(method)
307
+ method.source_location.first =~ /forwardable\.rb/
308
+ end
309
+
264
310
  # memoized lines for file
265
311
  def lines_for_file(file)
266
312
  @lines_for_file ||= {}
@@ -271,17 +317,5 @@ class Pry
271
317
  @lines_for_file[file] ||= File.readlines(file)
272
318
  end
273
319
  end
274
-
275
- # FIXME: this method is also found in Pry::Method
276
- def safe_send(obj, method, *args, &block)
277
- (Module === obj ? Module : Object).instance_method(method).bind(obj).call(*args, &block)
278
- end
279
-
280
- # @param [String] doc The raw docstring to process.
281
- # @return [String] Process docstring markup and strip leading white space.
282
- def process_doc(doc)
283
- process_comment_markup(strip_leading_hash_and_whitespace_from_ruby_comments(doc))
284
- end
285
-
286
320
  end
287
321
  end
@@ -1,46 +1,30 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/pry/version', __FILE__)
2
3
 
3
4
  Gem::Specification.new do |s|
4
- s.name = "pry"
5
- s.version = "0.9.10pre1"
5
+ s.name = "pry"
6
+ s.version = Pry::VERSION
6
7
 
7
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["John Mair (banisterfiend)", "Conrad Irwin"]
9
- s.date = "2012-07-13"
10
- s.description = "An IRB alternative and runtime developer console"
11
- s.email = ["jrmair@gmail.com", "conrad.irwin@gmail.com"]
12
- s.executables = ["pry"]
13
- s.files = [".document", ".gemtest", ".gitignore", ".travis.yml", ".yardopts", "CHANGELOG", "CONTRIBUTORS", "Gemfile", "LICENSE", "README.markdown", "Rakefile", "TODO", "bin/pry", "examples/example_basic.rb", "examples/example_command_override.rb", "examples/example_commands.rb", "examples/example_hooks.rb", "examples/example_image_edit.rb", "examples/example_input.rb", "examples/example_input2.rb", "examples/example_output.rb", "examples/example_print.rb", "examples/example_prompt.rb", "examples/helper.rb", "lib/pry.rb", "lib/pry/cli.rb", "lib/pry/code.rb", "lib/pry/command.rb", "lib/pry/command_set.rb", "lib/pry/commands.rb", "lib/pry/completion.rb", "lib/pry/config.rb", "lib/pry/core_extensions.rb", "lib/pry/custom_completions.rb", "lib/pry/default_commands/cd.rb", "lib/pry/default_commands/commands.rb", "lib/pry/default_commands/context.rb", "lib/pry/default_commands/easter_eggs.rb", "lib/pry/default_commands/editing.rb", "lib/pry/default_commands/find_method.rb", "lib/pry/default_commands/gems.rb", "lib/pry/default_commands/gist.rb", "lib/pry/default_commands/help.rb", "lib/pry/default_commands/hist.rb", "lib/pry/default_commands/input_and_output.rb", "lib/pry/default_commands/introspection.rb", "lib/pry/default_commands/ls.rb", "lib/pry/default_commands/misc.rb", "lib/pry/default_commands/navigating_pry.rb", "lib/pry/default_commands/whereami.rb", "lib/pry/extended_commands/experimental.rb", "lib/pry/helpers.rb", "lib/pry/helpers/base_helpers.rb", "lib/pry/helpers/command_helpers.rb", "lib/pry/helpers/documentation_helpers.rb", "lib/pry/helpers/options_helpers.rb", "lib/pry/helpers/text.rb", "lib/pry/history.rb", "lib/pry/history_array.rb", "lib/pry/hooks.rb", "lib/pry/indent.rb", "lib/pry/method.rb", "lib/pry/module_candidate.rb", "lib/pry/plugins.rb", "lib/pry/pry_class.rb", "lib/pry/pry_instance.rb", "lib/pry/rbx_method.rb", "lib/pry/rbx_path.rb", "lib/pry/repl_file_loader.rb", "lib/pry/version.rb", "lib/pry/wrapped_module.rb", "man/pry.1", "man/pry.1.html", "man/pry.1.ronn", "pry.gemspec", "test/candidate_helper1.rb", "test/candidate_helper2.rb", "test/helper.rb", "test/test_cli.rb", "test/test_code.rb", "test/test_command.rb", "test/test_command_helpers.rb", "test/test_command_integration.rb", "test/test_command_set.rb", "test/test_completion.rb", "test/test_control_d_handler.rb", "test/test_default_commands/example.erb", "test/test_default_commands/test_cd.rb", "test/test_default_commands/test_context.rb", "test/test_default_commands/test_documentation.rb", "test/test_default_commands/test_find_method.rb", "test/test_default_commands/test_gems.rb", "test/test_default_commands/test_help.rb", "test/test_default_commands/test_input.rb", "test/test_default_commands/test_introspection.rb", "test/test_default_commands/test_ls.rb", "test/test_default_commands/test_shell.rb", "test/test_default_commands/test_show_source.rb", "test/test_exception_whitelist.rb", "test/test_history_array.rb", "test/test_hooks.rb", "test/test_indent.rb", "test/test_input_stack.rb", "test/test_method.rb", "test/test_prompt.rb", "test/test_pry.rb", "test/test_pry_defaults.rb", "test/test_pry_history.rb", "test/test_pry_output.rb", "test/test_sticky_locals.rb", "test/test_syntax_checking.rb", "test/test_wrapped_module.rb", "test/testrc", "test/testrcbad", "wiki/Customizing-pry.md", "wiki/Home.md"]
8
+ s.authors = ["John Mair (banisterfiend)", "Conrad Irwin", "Ryan Fitzgerald"]
9
+ s.email = ["jrmair@gmail.com", "conrad.irwin@gmail.com", "rwfitzge@gmail.com"]
10
+ s.summary = "An IRB alternative and runtime developer console"
11
+ s.description = s.summary
14
12
  s.homepage = "http://pry.github.com"
13
+
14
+ s.executables = ["pry"]
15
15
  s.require_paths = ["lib"]
16
- s.rubygems_version = "1.8.24"
17
- s.summary = "An IRB alternative and runtime developer console"
18
- s.test_files = ["test/candidate_helper1.rb", "test/candidate_helper2.rb", "test/helper.rb", "test/test_cli.rb", "test/test_code.rb", "test/test_command.rb", "test/test_command_helpers.rb", "test/test_command_integration.rb", "test/test_command_set.rb", "test/test_completion.rb", "test/test_control_d_handler.rb", "test/test_default_commands/example.erb", "test/test_default_commands/test_cd.rb", "test/test_default_commands/test_context.rb", "test/test_default_commands/test_documentation.rb", "test/test_default_commands/test_find_method.rb", "test/test_default_commands/test_gems.rb", "test/test_default_commands/test_help.rb", "test/test_default_commands/test_input.rb", "test/test_default_commands/test_introspection.rb", "test/test_default_commands/test_ls.rb", "test/test_default_commands/test_shell.rb", "test/test_default_commands/test_show_source.rb", "test/test_exception_whitelist.rb", "test/test_history_array.rb", "test/test_hooks.rb", "test/test_indent.rb", "test/test_input_stack.rb", "test/test_method.rb", "test/test_prompt.rb", "test/test_pry.rb", "test/test_pry_defaults.rb", "test/test_pry_history.rb", "test/test_pry_output.rb", "test/test_sticky_locals.rb", "test/test_syntax_checking.rb", "test/test_wrapped_module.rb", "test/testrc", "test/testrcbad"]
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- spec/*`.split("\n")
19
18
 
20
- if s.respond_to? :specification_version then
21
- s.specification_version = 3
19
+ s.add_dependency 'coderay', '~> 1.0.5'
20
+ s.add_dependency 'slop', '~> 3.4'
21
+ s.add_dependency 'method_source', '~> 0.8'
22
22
 
23
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
24
- s.add_runtime_dependency(%q<coderay>, ["~> 1.0.5"])
25
- s.add_runtime_dependency(%q<slop>, ["~> 3.3.1"])
26
- s.add_runtime_dependency(%q<method_source>, ["~> 0.8"])
27
- s.add_development_dependency(%q<bacon>, ["~> 1.1"])
28
- s.add_development_dependency(%q<open4>, ["~> 1.3"])
29
- s.add_development_dependency(%q<rake>, ["~> 0.9"])
30
- else
31
- s.add_dependency(%q<coderay>, ["~> 1.0.5"])
32
- s.add_dependency(%q<slop>, ["~> 3.3.1"])
33
- s.add_dependency(%q<method_source>, ["~> 0.8"])
34
- s.add_dependency(%q<bacon>, ["~> 1.1"])
35
- s.add_dependency(%q<open4>, ["~> 1.3"])
36
- s.add_dependency(%q<rake>, ["~> 0.9"])
37
- end
38
- else
39
- s.add_dependency(%q<coderay>, ["~> 1.0.5"])
40
- s.add_dependency(%q<slop>, ["~> 3.3.1"])
41
- s.add_dependency(%q<method_source>, ["~> 0.8"])
42
- s.add_dependency(%q<bacon>, ["~> 1.1"])
43
- s.add_dependency(%q<open4>, ["~> 1.3"])
44
- s.add_dependency(%q<rake>, ["~> 0.9"])
45
- end
23
+ s.add_development_dependency 'bacon', '~> 1.2'
24
+ s.add_development_dependency 'open4', '~> 1.3'
25
+ s.add_development_dependency 'rake', '~> 0.9'
26
+ s.add_development_dependency 'guard', '~> 1.3.2'
27
+ s.add_development_dependency 'mocha', '~> 0.13.1'
28
+ # TODO: make this a plain dependency:
29
+ s.add_development_dependency 'bond', '~> 0.4.2'
46
30
  end