pry-doc 0.6.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +119 -0
  3. data/.gitignore +6 -0
  4. data/CHANGELOG.md +78 -0
  5. data/README.md +9 -8
  6. data/Rakefile +59 -12
  7. data/lib/pry-doc/{core_docs_20 → docs/20}/checksums +0 -0
  8. data/lib/pry-doc/{core_docs_20 → docs/20}/object_types +0 -0
  9. data/lib/pry-doc/{core_docs_20 → docs/20}/objects/root.dat +0 -0
  10. data/lib/pry-doc/{core_docs_19 → docs/20}/proxy_types +0 -0
  11. data/lib/pry-doc/{core_docs_21 → docs/21}/checksums +0 -0
  12. data/lib/pry-doc/{core_docs_21 → docs/21}/object_types +0 -0
  13. data/lib/pry-doc/{core_docs_21 → docs/21}/objects/root.dat +0 -0
  14. data/lib/pry-doc/{core_docs_20 → docs/21}/proxy_types +0 -0
  15. data/lib/pry-doc/docs/22/checksums +474 -0
  16. data/lib/pry-doc/docs/22/object_types +0 -0
  17. data/lib/pry-doc/{core_docs_19 → docs/22}/objects/root.dat +0 -0
  18. data/lib/pry-doc/{core_docs_21 → docs/22}/proxy_types +0 -0
  19. data/lib/pry-doc/docs/23/checksums +481 -0
  20. data/lib/pry-doc/docs/23/object_types +0 -0
  21. data/lib/pry-doc/docs/23/objects/root.dat +0 -0
  22. data/lib/pry-doc/docs/23/proxy_types +0 -0
  23. data/lib/pry-doc/docs/24/checksums +486 -0
  24. data/lib/pry-doc/docs/24/complete +0 -0
  25. data/lib/pry-doc/docs/24/object_types +0 -0
  26. data/lib/pry-doc/docs/24/objects/root.dat +0 -0
  27. data/lib/pry-doc/docs/24/proxy_types +0 -0
  28. data/lib/pry-doc/docs/25/checksums +493 -0
  29. data/lib/pry-doc/docs/25/complete +0 -0
  30. data/lib/pry-doc/docs/25/object_types +0 -0
  31. data/lib/pry-doc/docs/25/objects/root.dat +0 -0
  32. data/lib/pry-doc/docs/25/proxy_types +0 -0
  33. data/lib/pry-doc/docs/26/checksums +501 -0
  34. data/lib/pry-doc/docs/26/complete +0 -0
  35. data/lib/pry-doc/docs/26/object_types +0 -0
  36. data/lib/pry-doc/docs/26/objects/root.dat +0 -0
  37. data/lib/pry-doc/docs/26/proxy_types +0 -0
  38. data/lib/pry-doc/docs/27/checksums +506 -0
  39. data/lib/pry-doc/docs/27/complete +0 -0
  40. data/lib/pry-doc/docs/27/object_types +0 -0
  41. data/lib/pry-doc/docs/27/objects/root.dat +0 -0
  42. data/lib/pry-doc/docs/27/proxy_types +0 -0
  43. data/lib/pry-doc/docs/30/checksums +557 -0
  44. data/lib/pry-doc/docs/30/complete +0 -0
  45. data/lib/pry-doc/docs/30/object_types +0 -0
  46. data/lib/pry-doc/docs/30/objects/root.dat +0 -0
  47. data/lib/pry-doc/docs/30/proxy_types +0 -0
  48. data/lib/pry-doc/docs/31/checksums +522 -0
  49. data/lib/pry-doc/docs/31/complete +0 -0
  50. data/lib/pry-doc/docs/31/object_types +0 -0
  51. data/lib/pry-doc/docs/31/objects/root.dat +0 -0
  52. data/lib/pry-doc/docs/31/proxy_types +0 -0
  53. data/lib/pry-doc/pry_ext/method_info.rb +231 -0
  54. data/lib/pry-doc/pry_ext/show_source_with_c_internals/c_file.rb +91 -0
  55. data/lib/pry-doc/pry_ext/show_source_with_c_internals/code_fetcher.rb +89 -0
  56. data/lib/pry-doc/pry_ext/show_source_with_c_internals/etag_parser.rb +58 -0
  57. data/lib/pry-doc/pry_ext/show_source_with_c_internals/ruby_source_installer.rb +92 -0
  58. data/lib/pry-doc/pry_ext/show_source_with_c_internals/symbol_extractor.rb +111 -0
  59. data/lib/pry-doc/pry_ext/show_source_with_c_internals.rb +54 -0
  60. data/lib/pry-doc/version.rb +1 -1
  61. data/lib/pry-doc.rb +17 -223
  62. data/libexec/linux/etags-32 +0 -0
  63. data/libexec/linux/etags-64 +0 -0
  64. data/libexec/windows/etags.exe +0 -0
  65. data/pry-doc.gemspec +7 -4
  66. data/spec/fixtures/c_source/TAGS +22 -0
  67. data/spec/fixtures/c_source/goodbye.c +4 -0
  68. data/spec/fixtures/c_source/hello.c +43 -0
  69. data/spec/gem_with_cext/gems/ext/sample.c +5 -7
  70. data/spec/gem_with_cext/gems/lib/sample.rb +5 -5
  71. data/spec/helper.rb +8 -1
  72. data/spec/pry-doc_spec.rb +253 -46
  73. metadata +90 -30
  74. data/lib/pry-doc/core_docs_19/checksums +0 -226
  75. data/lib/pry-doc/core_docs_19/object_types +0 -0
@@ -0,0 +1,54 @@
1
+ require_relative "show_source_with_c_internals/code_fetcher"
2
+
3
+ module Pry::CInternals
4
+ class ShowSourceWithCInternals < Pry::Command::ShowSource
5
+ def options(opt)
6
+ super(opt)
7
+ opt.on :c, "c-source", "Show source of a C identifier in MRI (rather than Ruby method of same name)"
8
+ end
9
+
10
+ def show_c_source
11
+ if opts.present?(:all)
12
+ result, file = CodeFetcher.new(line_number_style: line_number_style)
13
+ .fetch_all_definitions(obj_name)
14
+ else
15
+ result, file = CodeFetcher.new(line_number_style: line_number_style)
16
+ .fetch_first_definition(obj_name)
17
+ end
18
+ if result
19
+ set_file_and_dir_locals(file)
20
+ pry_instance.pager.page result
21
+ else
22
+ raise Pry::CommandError, no_definition_message
23
+ end
24
+ end
25
+
26
+ def process
27
+ if opts.present?(:c) && !pry_instance.config.skip_cruby_source
28
+ show_c_source
29
+ return
30
+ else
31
+ super
32
+ end
33
+ rescue Pry::CommandError
34
+ raise if pry_instance.config.skip_cruby_source
35
+ show_c_source
36
+ end
37
+
38
+ private
39
+
40
+ # We can number lines with their actual line numbers
41
+ # or starting with 1 (base-one)
42
+ def line_number_style
43
+ if opts.present?(:'base-one')
44
+ :'base-one'
45
+ elsif opts.present?(:'line-numbers')
46
+ :'line-numbers'
47
+ else
48
+ nil
49
+ end
50
+ end
51
+
52
+ Pry::Commands.add_command(ShowSourceWithCInternals)
53
+ end
54
+ end
@@ -1,3 +1,3 @@
1
1
  module PryDoc
2
- VERSION = '0.6.0'
2
+ VERSION = '1.3.0'.freeze
3
3
  end
data/lib/pry-doc.rb CHANGED
@@ -1,232 +1,26 @@
1
- # pry-doc.rb
2
- # (C) John Mair (banisterfiend); MIT license
3
-
4
- direc = File.dirname(__FILE__)
5
-
6
- require "#{direc}/pry-doc/version"
7
- require "yard"
8
-
9
1
  module PryDoc
10
-
11
2
  def self.load_yardoc(version)
12
- path = "#{File.dirname(__FILE__)}/pry-doc/core_docs_#{ version }"
13
- YARD::Registry.load_yardoc(path)
14
- end
15
-
16
- end
17
-
18
- case RUBY_VERSION
19
- when /\A2\.1/
20
- PryDoc.load_yardoc('21')
21
- when /\A2\.0/
22
- PryDoc.load_yardoc('20')
23
- else
24
- PryDoc.load_yardoc('19')
25
- end
26
-
27
- class Pry
28
-
29
- # do not use pry-doc if rbx is active
30
- if !Object.const_defined?(:RUBY_ENGINE) || RUBY_ENGINE !~ /rbx/
31
- self.config.has_pry_doc = true
32
- end
33
-
34
- module MethodInfo
35
-
36
- # Convert a method object into the `Class#method` string notation.
37
- # @param [Method, UnboundMethod] meth
38
- # @return [String] The method in string receiver notation.
39
- # @note This mess is needed in order to support all the modern Rubies. YOU
40
- # must figure out a better way to distinguish between class methods and
41
- # instance methods.
42
- def self.receiver_notation_for(meth)
43
- match = meth.inspect.match(/\A#<(?:Unbound)?Method: (.+)([#\.].+)>\z/)
44
- owner = meth.owner.to_s.sub(/#<.+?:(.+?)>/, '\1')
45
- name = match[2]
46
- name.sub!('#', '.') if match[1] =~ /\A#<Class:/
47
- owner + name
3
+ path = "#{File.dirname(__FILE__)}/pry-doc/docs/#{version}"
4
+ unless File.directory?(path)
5
+ puts "#{RUBY_ENGINE}/#{RUBY_VERSION} isn't supported by this pry-doc version"
48
6
  end
49
7
 
50
- # Retrives aliases of a method
51
- # @param [Method, UnboundMethod] meth The method object.
52
- # @return [Array] The aliases of a method if it exists
53
- # otherwise, return empty array
54
- def self.aliases(meth)
55
- host = is_singleton?(meth) ? meth.receiver : meth.owner
56
- method_type = is_singleton?(meth) ? :method : :instance_method
57
-
58
- methods = Pry::Method.send(:all_from_common, host, method_type, false).
59
- map { |m| m.instance_variable_get(:@method) }
60
-
61
- methods.select { |m| host.send(method_type,m.name) == host.send(method_type,meth.name) }.
62
- reject { |m| m.name == meth.name }.
63
- map { |m| host.send(method_type,m.name) }
64
- end
8
+ # Do not use pry-doc if Rubinius is active.
9
+ Pry.config.has_pry_doc = RUBY_ENGINE !~ /rbx/
65
10
 
66
- # Checks whether method is a singleton (i.e class method)
67
- # @param [Method, UnboundMethod] meth
68
- # @param [Boolean] true if singleton
69
- def self.is_singleton?(meth)
70
- receiver_notation_for(meth).include?('.')
71
- end
72
-
73
- # Check whether the file containing the method is already cached.
74
- # @param [Method, UnboundMethod] meth The method object.
75
- # @return [Boolean] Whether the method is cached.
76
- def self.cached?(meth)
77
- !!registry_lookup(meth)
78
- end
79
-
80
- def self.registry_lookup(meth)
81
- obj = YARD::Registry.at(receiver_notation_for(meth))
82
- if obj.nil?
83
- if !(aliases = aliases(meth)).empty?
84
- obj = YARD::Registry.at(receiver_notation_for(aliases.first))
85
- elsif meth.owner == Kernel
86
- # YARD thinks that some methods are on Object when
87
- # they're actually on Kernel; so try again on Object if Kernel fails.
88
- obj = YARD::Registry.at("Object##{meth.name}")
89
- end
90
- end
91
- obj
92
- end
93
-
94
- # Retrieve the YARD object that contains the method data.
95
- # @param [Method, UnboundMethod] meth The method object.
96
- # @return [YARD::CodeObjects::MethodObject] The YARD data for the method.
97
- def self.info_for(meth)
98
- cache(meth)
99
- registry_lookup(meth)
100
- end
101
-
102
- # Determine whether a method is an eval method.
103
- # @return [Boolean] Whether the method is an eval method.
104
- def self.is_eval_method?(meth)
105
- file, _ = meth.source_location
106
- if file =~ /(\(.*\))|<.*>/
107
- true
108
- else
109
- false
110
- end
111
- end
112
-
113
- # Attempts to find the c source files if method belongs to a gem
114
- # and use YARD to parse and cache the source files for display
115
- #
116
- # @param [Method, UnboundMethod] meth The method object.
117
- def self.parse_and_cache_if_gem_cext(meth)
118
- if gem_dir = find_gem_dir(meth)
119
- if c_files_found?(gem_dir)
120
- warn "Scanning and caching *.c files..."
121
- YARD.parse("#{gem_dir}/**/*.c")
122
- end
123
- end
124
- end
125
-
126
- # @param [String] root directory path of gem that method belongs to
127
- # @return [Boolean] true if c files exist?
128
- def self.c_files_found?(gem_dir)
129
- Dir.glob("#{gem_dir}/**/*.c").count > 0
130
- end
131
-
132
- # @return [Object] The host of the method (receiver or owner).
133
- def self.method_host(meth)
134
- is_singleton?(meth) && Module === meth.receiver ? meth.receiver : meth.owner
135
- end
136
-
137
- # FIXME: this is unnecessarily limited to ext/ and lib/ folders
138
- # @return [String] The root folder of a given gem directory.
139
- def self.gem_root(dir)
140
- if index = dir.rindex(/\/(?:lib|ext)(?:\/|$)/)
141
- dir[0..index-1]
142
- end
143
- end
144
-
145
- # @param [Method, UnboundMethod] meth The method object.
146
- # @return [String] root directory path of gem that method belongs to,
147
- # nil if could not be found
148
- def self.find_gem_dir(meth)
149
- host = method_host(meth)
150
-
151
- begin
152
- host_source_location, _ = WrappedModule.new(host).source_location
153
- break if host_source_location != nil
154
- return unless host.name
155
- host = eval(host.namespace_name)
156
- end while host
157
-
158
- # we want to exclude all source_locations that aren't gems (i.e
159
- # stdlib)
160
- if host_source_location && host_source_location =~ %r{/gems/}
161
- gem_root(host_source_location)
162
- else
163
-
164
- # the WrappedModule approach failed, so try our backup approach
165
- gem_dir_from_method(meth)
166
- end
167
- end
168
-
169
- # Try to guess what the gem name will be based on the name of the module.
170
- # We try a few approaches here depending on the `guess` parameter.
171
- # @param [String] name The name of the module.
172
- # @param [Fixnum] guess The current guessing approach to use.
173
- # @return [String, nil] The guessed gem name, or `nil` if out of guesses.
174
- def self.guess_gem_name_from_module_name(name, guess)
175
- case guess
176
- when 0
177
- name.downcase
178
- when 1
179
- name.scan(/[A-Z][a-z]+/).map(&:downcase).join('_')
180
- when 2
181
- name.scan(/[A-Z][a-z]+/).map(&:downcase).join('_').sub("_", "-")
182
- when 3
183
- name.scan(/[A-Z][a-z]+/).map(&:downcase).join('-')
184
- when 4
185
- name
186
- else
187
- nil
188
- end
189
- end
190
-
191
- # Try to recover the gem directory of a gem based on a method object.
192
- # @param [Method, UnboundMethod] meth The method object.
193
- # @return [String, nil] The located gem directory.
194
- def self.gem_dir_from_method(meth)
195
- guess = 0
196
-
197
- host = method_host(meth)
198
- return unless host.name
199
- root_module_name = host.name.split("::").first
200
- while gem_name = guess_gem_name_from_module_name(root_module_name, guess)
201
- matches = $LOAD_PATH.grep %r{/gems/#{gem_name}} if !gem_name.empty?
202
- if matches && matches.any?
203
- return gem_root(matches.first)
204
- else
205
- guess += 1
206
- end
207
- end
208
-
209
- nil
210
- end
11
+ YARD::Registry.load_yardoc(path)
12
+ end
211
13
 
212
- # Cache the file that holds the method or return immediately if file is
213
- # already cached. Return if the method cannot be cached -
214
- # i.e is a C stdlib method.
215
- # @param [Method, UnboundMethod] meth The method object.
216
- def self.cache(meth)
217
- file, _ = meth.source_location
14
+ def self.root
15
+ @root ||= File.expand_path(File.dirname(__dir__))
16
+ end
218
17
 
219
- return if is_eval_method?(meth)
220
- return if cached?(meth)
18
+ root
19
+ end
221
20
 
222
- if !file
223
- parse_and_cache_if_gem_cext(meth)
224
- return
225
- end
21
+ require 'yard'
22
+ require 'pry'
23
+ require 'pry-doc/version'
24
+ require 'pry-doc/pry_ext/method_info'
226
25
 
227
- log.enter_level(Logger::FATAL) do
228
- YARD.parse(file)
229
- end
230
- end
231
- end
232
- end
26
+ PryDoc.load_yardoc(RUBY_VERSION[0...3].sub!('.', ''))
Binary file
Binary file
Binary file
data/pry-doc.gemspec CHANGED
@@ -20,8 +20,11 @@ DESCR
20
20
  s.require_paths = ["lib"]
21
21
  s.files = `git ls-files`.split("\n")
22
22
 
23
- s.add_dependency 'yard', "~> 0.8"
24
- s.add_dependency 'pry', "~> 0.9"
25
- s.add_development_dependency 'latest_ruby', "~> 0.0"
26
- s.add_development_dependency 'bacon', "~> 1.1"
23
+ s.required_ruby_version = '>= 2.0'
24
+
25
+ s.add_dependency 'yard', "~> 0.9.11"
26
+ s.add_dependency 'pry', "~> 0.11"
27
+ s.add_development_dependency 'latest_ruby', '~> 3.1'
28
+ s.add_development_dependency 'rspec', '~> 3.5'
29
+ s.add_development_dependency 'rake', "~> 10.0"
27
30
  end
@@ -0,0 +1,22 @@
1
+
2
+ goodbye.c,9
3
+ foo(2,5
4
+
5
+ hello.c,309
6
+ foo(2,4
7
+ #define baby 5,19
8
+ typedef int wassup;9,73
9
+ enum bar 11,94
10
+ alpha,12,105
11
+ beta,13,114
12
+ gamma14,122
13
+ struct baz 17,134
14
+ typedef enum cute_enum_e 22,169
15
+ lillybing,23,196
16
+ tote,24,209
17
+ lilt25,217
18
+ } baby_enum;26,224
19
+ } cutie_pie;31,283
20
+ void tinkywinky(33,297
21
+ void lala(36,324
22
+ po(41,350
@@ -0,0 +1,4 @@
1
+ char
2
+ foo(int*) {
3
+ return 'a';
4
+ }
@@ -0,0 +1,43 @@
1
+ int
2
+ foo(void) {
3
+ }
4
+
5
+ #define baby do { \
6
+ printf("baby"); \
7
+ } while(0)
8
+
9
+ typedef int wassup;
10
+
11
+ enum bar {
12
+ alpha,
13
+ beta,
14
+ gamma
15
+ };
16
+
17
+ struct baz {
18
+ int x;
19
+ int y;
20
+ };
21
+
22
+ typedef enum cute_enum_e {
23
+ lillybing,
24
+ tote,
25
+ lilt
26
+ } baby_enum;
27
+
28
+ typedef struct {
29
+ int lovely;
30
+ char horse;
31
+ } cutie_pie;
32
+
33
+ void tinkywinky(void) {
34
+ }
35
+
36
+ void lala(void)
37
+ {
38
+ }
39
+
40
+ int*
41
+ po(void)
42
+ {
43
+ }
@@ -1,8 +1,8 @@
1
1
  #include "ruby.h"
2
2
 
3
- static VALUE unlink(VALUE self)
3
+ static VALUE gleezor(VALUE self)
4
4
  {
5
- return 1;
5
+ return INT2FIX(1);
6
6
  }
7
7
 
8
8
  void Init_sample(void)
@@ -11,9 +11,7 @@ void Init_sample(void)
11
11
  VALUE A = rb_define_module_under(klass, "A");
12
12
  VALUE B = rb_define_module_under(A, "B");
13
13
 
14
- rb_define_method(klass, "unlink", unlink, 0);
15
- rb_define_method(B, "unlink", unlink, 0);
16
- rb_define_singleton_method(B, "unlink", unlink, 0);
14
+ rb_define_method(klass, "gleezor", gleezor, 0);
15
+ rb_define_method(B, "gleezor", gleezor, 0);
16
+ rb_define_singleton_method(B, "gleezor", gleezor, 0);
17
17
  }
18
-
19
-
@@ -3,16 +3,16 @@ class Sample
3
3
  def some_meth; end
4
4
 
5
5
  # aliasing a C method
6
- alias :remove :unlink
6
+ alias :remove :gleezor
7
7
 
8
8
  protected
9
9
 
10
- def unlink_1; end
11
- alias :remove_1 :unlink_1
10
+ def gleezor_1; end
11
+ alias :remove_1 :gleezor_1
12
12
 
13
13
  private
14
14
 
15
- def unlink_2; end
15
+ def gleezor_2; end
16
16
 
17
- alias :remove_2 :unlink_2
17
+ alias :remove_2 :gleezor_2
18
18
  end
data/spec/helper.rb CHANGED
@@ -1,3 +1,11 @@
1
+ require 'pry-doc'
2
+
3
+ RSpec.configure do |c|
4
+ c.order = 'random'
5
+ c.color = true
6
+ c.disable_monkey_patching!
7
+ end
8
+
1
9
  direc = File.dirname(__FILE__)
2
10
 
3
11
  class C
@@ -8,4 +16,3 @@ puts
8
16
  puts "Building Sample Gem with C Extensions for testing.."
9
17
  system("cd #{direc}/gem_with_cext/gems/ext/ && ruby extconf.rb && make")
10
18
  puts
11
-