yard 0.9.21 → 0.9.26

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of yard might be problematic. Click here for more details.

Files changed (250) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +0 -0
  3. data/.gitattributes +4 -0
  4. data/.github/FUNDING.yml +3 -0
  5. data/.github/ISSUE_TEMPLATE.md +6 -6
  6. data/.github/PULL_REQUEST_TEMPLATE.md +5 -5
  7. data/.github/workflows/ci.yml +42 -0
  8. data/.github/workflows/gem.yml +27 -0
  9. data/.gitignore +0 -0
  10. data/.rspec +0 -0
  11. data/.rubocop.yml +37 -24
  12. data/.travis.yml +0 -3
  13. data/.yardopts +0 -0
  14. data/.yardopts_guide +0 -0
  15. data/.yardopts_i18n +0 -0
  16. data/CHANGELOG.md +47 -4
  17. data/CONTRIBUTING.md +2 -2
  18. data/Gemfile +4 -3
  19. data/README.md +97 -102
  20. data/Rakefile +2 -0
  21. data/lib/yard/cli/diff.rb +4 -1
  22. data/lib/yard/cli/server.rb +22 -13
  23. data/lib/yard/code_objects/method_object.rb +1 -1
  24. data/lib/yard/code_objects/namespace_mapper.rb +30 -3
  25. data/lib/yard/code_objects/proxy.rb +2 -1
  26. data/lib/yard/globals.rb +1 -1
  27. data/lib/yard/handlers/c/base.rb +35 -0
  28. data/lib/yard/handlers/ruby/mixin_handler.rb +4 -1
  29. data/lib/yard/parser/ruby/legacy/irb/slex.rb +1 -1
  30. data/lib/yard/parser/ruby/ruby_parser.rb +6 -4
  31. data/lib/yard/parser/ruby/token_resolver.rb +3 -1
  32. data/lib/yard/parser/source_parser.rb +1 -1
  33. data/lib/yard/registry_resolver.rb +10 -24
  34. data/lib/yard/registry_store.rb +1 -1
  35. data/lib/yard/serializers/yardoc_serializer.rb +1 -1
  36. data/lib/yard/server/commands/base.rb +2 -2
  37. data/lib/yard/templates/helpers/html_helper.rb +10 -3
  38. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +1 -1
  39. data/lib/yard/templates/helpers/markup/rdoc_markup.rb +5 -4
  40. data/lib/yard/templates/section.rb +1 -3
  41. data/lib/yard/version.rb +1 -1
  42. data/samus.json +15 -46
  43. data/tasks/update_error_map.rake +53 -0
  44. data/templates/default/fulldoc/html/css/style.css +1 -0
  45. data/templates/default/fulldoc/html/js/jquery.js +4 -2
  46. data/yard.gemspec +1 -2
  47. metadata +9 -206
  48. data/spec/cli/command_parser_spec.rb +0 -43
  49. data/spec/cli/command_spec.rb +0 -36
  50. data/spec/cli/config_spec.rb +0 -148
  51. data/spec/cli/diff_spec.rb +0 -254
  52. data/spec/cli/display_spec.rb +0 -30
  53. data/spec/cli/gems_spec.rb +0 -81
  54. data/spec/cli/graph_spec.rb +0 -18
  55. data/spec/cli/help_spec.rb +0 -22
  56. data/spec/cli/i18n_spec.rb +0 -107
  57. data/spec/cli/list_spec.rb +0 -8
  58. data/spec/cli/markup_types_spec.rb +0 -22
  59. data/spec/cli/server_spec.rb +0 -324
  60. data/spec/cli/stats_spec.rb +0 -96
  61. data/spec/cli/yard_on_yard_spec.rb +0 -38
  62. data/spec/cli/yardoc_spec.rb +0 -896
  63. data/spec/cli/yri_spec.rb +0 -101
  64. data/spec/code_objects/base_spec.rb +0 -485
  65. data/spec/code_objects/class_object_spec.rb +0 -226
  66. data/spec/code_objects/code_object_list_spec.rb +0 -36
  67. data/spec/code_objects/constants_spec.rb +0 -116
  68. data/spec/code_objects/extra_file_object_spec.rb +0 -161
  69. data/spec/code_objects/macro_object_spec.rb +0 -150
  70. data/spec/code_objects/method_object_spec.rb +0 -184
  71. data/spec/code_objects/module_object_spec.rb +0 -142
  72. data/spec/code_objects/namespace_object_spec.rb +0 -171
  73. data/spec/code_objects/proxy_spec.rb +0 -147
  74. data/spec/code_objects/spec_helper.rb +0 -3
  75. data/spec/config_spec.rb +0 -171
  76. data/spec/core_ext/array_spec.rb +0 -13
  77. data/spec/core_ext/file_spec.rb +0 -72
  78. data/spec/core_ext/hash_spec.rb +0 -14
  79. data/spec/core_ext/insertion_spec.rb +0 -37
  80. data/spec/core_ext/module_spec.rb +0 -9
  81. data/spec/core_ext/string_spec.rb +0 -42
  82. data/spec/core_ext/symbol_hash_spec.rb +0 -89
  83. data/spec/docstring_parser_spec.rb +0 -280
  84. data/spec/docstring_spec.rb +0 -373
  85. data/spec/handlers/alias_handler_spec.rb +0 -82
  86. data/spec/handlers/attribute_handler_spec.rb +0 -96
  87. data/spec/handlers/base_spec.rb +0 -216
  88. data/spec/handlers/c/alias_handler_spec.rb +0 -34
  89. data/spec/handlers/c/attribute_handler_spec.rb +0 -41
  90. data/spec/handlers/c/class_handler_spec.rb +0 -78
  91. data/spec/handlers/c/constant_handler_spec.rb +0 -71
  92. data/spec/handlers/c/init_handler_spec.rb +0 -48
  93. data/spec/handlers/c/method_handler_spec.rb +0 -327
  94. data/spec/handlers/c/mixin_handler_spec.rb +0 -44
  95. data/spec/handlers/c/module_handler_spec.rb +0 -71
  96. data/spec/handlers/c/override_comment_handler_spec.rb +0 -47
  97. data/spec/handlers/c/path_handler_spec.rb +0 -36
  98. data/spec/handlers/c/spec_helper.rb +0 -23
  99. data/spec/handlers/c/struct_handler_spec.rb +0 -16
  100. data/spec/handlers/class_condition_handler_spec.rb +0 -87
  101. data/spec/handlers/class_handler_spec.rb +0 -247
  102. data/spec/handlers/class_method_handler_shared_examples.rb +0 -133
  103. data/spec/handlers/class_variable_handler_spec.rb +0 -12
  104. data/spec/handlers/constant_handler_spec.rb +0 -112
  105. data/spec/handlers/decorator_handler_methods_spec.rb +0 -393
  106. data/spec/handlers/dsl_handler_spec.rb +0 -226
  107. data/spec/handlers/examples/alias_handler_001.rb.txt +0 -46
  108. data/spec/handlers/examples/attribute_handler_001.rb.txt +0 -32
  109. data/spec/handlers/examples/class_condition_handler_001.rb.txt +0 -69
  110. data/spec/handlers/examples/class_handler_001.rb.txt +0 -120
  111. data/spec/handlers/examples/class_variable_handler_001.rb.txt +0 -10
  112. data/spec/handlers/examples/constant_handler_001.rb.txt +0 -35
  113. data/spec/handlers/examples/dsl_handler_001.rb.txt +0 -156
  114. data/spec/handlers/examples/exception_handler_001.rb.txt +0 -59
  115. data/spec/handlers/examples/extend_handler_001.rb.txt +0 -19
  116. data/spec/handlers/examples/method_condition_handler_001.rb.txt +0 -10
  117. data/spec/handlers/examples/method_handler_001.rb.txt +0 -128
  118. data/spec/handlers/examples/mixin_handler_001.rb.txt +0 -40
  119. data/spec/handlers/examples/module_handler_001.rb.txt +0 -29
  120. data/spec/handlers/examples/private_constant_handler_001.rb.txt +0 -8
  121. data/spec/handlers/examples/process_handler_001.rb.txt +0 -11
  122. data/spec/handlers/examples/visibility_handler_001.rb.txt +0 -36
  123. data/spec/handlers/examples/yield_handler_001.rb.txt +0 -54
  124. data/spec/handlers/exception_handler_spec.rb +0 -49
  125. data/spec/handlers/extend_handler_spec.rb +0 -28
  126. data/spec/handlers/legacy_base_spec.rb +0 -128
  127. data/spec/handlers/method_condition_handler_spec.rb +0 -15
  128. data/spec/handlers/method_handler_spec.rb +0 -214
  129. data/spec/handlers/mixin_handler_spec.rb +0 -60
  130. data/spec/handlers/module_function_handler_spec.rb +0 -106
  131. data/spec/handlers/module_handler_spec.rb +0 -35
  132. data/spec/handlers/private_class_method_handler_spec.rb +0 -11
  133. data/spec/handlers/private_constant_handler_spec.rb +0 -25
  134. data/spec/handlers/processor_spec.rb +0 -35
  135. data/spec/handlers/public_class_method_handler_spec.rb +0 -11
  136. data/spec/handlers/ruby/base_spec.rb +0 -95
  137. data/spec/handlers/ruby/legacy/base_spec.rb +0 -84
  138. data/spec/handlers/spec_helper.rb +0 -33
  139. data/spec/handlers/visibility_handler_spec.rb +0 -44
  140. data/spec/handlers/yield_handler_spec.rb +0 -52
  141. data/spec/i18n/locale_spec.rb +0 -81
  142. data/spec/i18n/message_spec.rb +0 -52
  143. data/spec/i18n/messages_spec.rb +0 -67
  144. data/spec/i18n/pot_generator_spec.rb +0 -295
  145. data/spec/i18n/text_spec.rb +0 -184
  146. data/spec/logging_spec.rb +0 -44
  147. data/spec/options_spec.rb +0 -171
  148. data/spec/parser/base_spec.rb +0 -24
  149. data/spec/parser/c_parser_spec.rb +0 -236
  150. data/spec/parser/examples/array.c.txt +0 -6267
  151. data/spec/parser/examples/example1.rb.txt +0 -8
  152. data/spec/parser/examples/extrafile.c.txt +0 -8
  153. data/spec/parser/examples/file.c.txt +0 -28
  154. data/spec/parser/examples/multifile.c.txt +0 -22
  155. data/spec/parser/examples/namespace.cpp.txt +0 -68
  156. data/spec/parser/examples/override.c.txt +0 -424
  157. data/spec/parser/examples/parse_in_order_001.rb.txt +0 -2
  158. data/spec/parser/examples/parse_in_order_002.rb.txt +0 -2
  159. data/spec/parser/examples/tag_handler_001.rb.txt +0 -8
  160. data/spec/parser/ruby/ast_node_spec.rb +0 -33
  161. data/spec/parser/ruby/legacy/statement_list_spec.rb +0 -299
  162. data/spec/parser/ruby/legacy/token_list_spec.rb +0 -79
  163. data/spec/parser/ruby/ruby_parser_spec.rb +0 -508
  164. data/spec/parser/ruby/token_resolver_spec.rb +0 -165
  165. data/spec/parser/source_parser_spec.rb +0 -727
  166. data/spec/parser/tag_parsing_spec.rb +0 -17
  167. data/spec/rake/yardoc_task_spec.rb +0 -118
  168. data/spec/registry_spec.rb +0 -463
  169. data/spec/registry_store_spec.rb +0 -327
  170. data/spec/rubygems/doc_manager_spec.rb +0 -112
  171. data/spec/serializers/data/serialized_yardoc/checksums +0 -1
  172. data/spec/serializers/data/serialized_yardoc/objects/Foo.dat +0 -0
  173. data/spec/serializers/data/serialized_yardoc/objects/Foo/bar_i.dat +0 -0
  174. data/spec/serializers/data/serialized_yardoc/objects/Foo/baz_i.dat +0 -0
  175. data/spec/serializers/data/serialized_yardoc/objects/root.dat +0 -0
  176. data/spec/serializers/data/serialized_yardoc/proxy_types +0 -2
  177. data/spec/serializers/file_system_serializer_spec.rb +0 -145
  178. data/spec/serializers/spec_helper.rb +0 -2
  179. data/spec/serializers/yardoc_serializer_spec.rb +0 -78
  180. data/spec/server/adapter_spec.rb +0 -39
  181. data/spec/server/commands/base_spec.rb +0 -91
  182. data/spec/server/commands/library_command_spec.rb +0 -39
  183. data/spec/server/doc_server_helper_spec.rb +0 -72
  184. data/spec/server/doc_server_serializer_spec.rb +0 -60
  185. data/spec/server/rack_adapter_spec.rb +0 -21
  186. data/spec/server/router_spec.rb +0 -123
  187. data/spec/server/spec_helper.rb +0 -22
  188. data/spec/server/static_caching_spec.rb +0 -47
  189. data/spec/server/webrick_servlet_spec.rb +0 -20
  190. data/spec/server_spec.rb +0 -19
  191. data/spec/spec_helper.rb +0 -212
  192. data/spec/tags/default_factory_spec.rb +0 -168
  193. data/spec/tags/default_tag_spec.rb +0 -11
  194. data/spec/tags/directives_spec.rb +0 -463
  195. data/spec/tags/library_spec.rb +0 -48
  196. data/spec/tags/overload_tag_spec.rb +0 -53
  197. data/spec/tags/ref_tag_list_spec.rb +0 -53
  198. data/spec/tags/types_explainer_spec.rb +0 -203
  199. data/spec/templates/class_spec.rb +0 -45
  200. data/spec/templates/constant_spec.rb +0 -41
  201. data/spec/templates/engine_spec.rb +0 -131
  202. data/spec/templates/examples/class001.html +0 -308
  203. data/spec/templates/examples/class001.txt +0 -36
  204. data/spec/templates/examples/class002.html +0 -39
  205. data/spec/templates/examples/constant001.txt +0 -25
  206. data/spec/templates/examples/constant002.txt +0 -7
  207. data/spec/templates/examples/constant003.txt +0 -11
  208. data/spec/templates/examples/method001.html +0 -137
  209. data/spec/templates/examples/method001.txt +0 -35
  210. data/spec/templates/examples/method002.html +0 -91
  211. data/spec/templates/examples/method002.txt +0 -20
  212. data/spec/templates/examples/method003.html +0 -165
  213. data/spec/templates/examples/method003.txt +0 -45
  214. data/spec/templates/examples/method004.html +0 -48
  215. data/spec/templates/examples/method004.txt +0 -10
  216. data/spec/templates/examples/method005.html +0 -105
  217. data/spec/templates/examples/method005.txt +0 -33
  218. data/spec/templates/examples/method006.html +0 -108
  219. data/spec/templates/examples/method006.txt +0 -20
  220. data/spec/templates/examples/module001.dot +0 -33
  221. data/spec/templates/examples/module001.html +0 -833
  222. data/spec/templates/examples/module001.txt +0 -33
  223. data/spec/templates/examples/module002.html +0 -341
  224. data/spec/templates/examples/module003.html +0 -202
  225. data/spec/templates/examples/module004.html +0 -394
  226. data/spec/templates/examples/module005.html +0 -82
  227. data/spec/templates/examples/tag001.txt +0 -82
  228. data/spec/templates/helpers/base_helper_spec.rb +0 -171
  229. data/spec/templates/helpers/html_helper_spec.rb +0 -687
  230. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +0 -65
  231. data/spec/templates/helpers/markup/rdoc_markup_spec.rb +0 -84
  232. data/spec/templates/helpers/markup_helper_spec.rb +0 -136
  233. data/spec/templates/helpers/method_helper_spec.rb +0 -107
  234. data/spec/templates/helpers/module_helper_spec.rb +0 -35
  235. data/spec/templates/helpers/shared_signature_examples.rb +0 -126
  236. data/spec/templates/helpers/text_helper_spec.rb +0 -65
  237. data/spec/templates/markup_processor_integrations/asciidoctor_spec.rb +0 -60
  238. data/spec/templates/markup_processor_integrations/integration_spec_helper.rb +0 -46
  239. data/spec/templates/markup_processor_integrations/rdoc_markdown_spec.rb +0 -59
  240. data/spec/templates/markup_processor_integrations/rdoc_spec.rb +0 -39
  241. data/spec/templates/markup_processor_integrations/redcarpet_spec.rb +0 -59
  242. data/spec/templates/markup_processor_integrations/redcloth_spec.rb +0 -48
  243. data/spec/templates/method_spec.rb +0 -118
  244. data/spec/templates/module_spec.rb +0 -203
  245. data/spec/templates/onefile_spec.rb +0 -66
  246. data/spec/templates/section_spec.rb +0 -144
  247. data/spec/templates/spec_helper.rb +0 -76
  248. data/spec/templates/tag_spec.rb +0 -52
  249. data/spec/templates/template_spec.rb +0 -410
  250. data/spec/verifier_spec.rb +0 -106
data/Rakefile CHANGED
@@ -6,6 +6,8 @@ require 'samus'
6
6
 
7
7
  YARD::VERSION.replace(ENV['YARD_VERSION']) if ENV['YARD_VERSION']
8
8
 
9
+ Dir['tasks/**/*.rake'].each { |task_file| load task_file }
10
+
9
11
  desc "Builds the gem"
10
12
  task :gem do
11
13
  sh "gem build yard.gemspec"
@@ -161,7 +161,10 @@ module YARD
161
161
  url = "http://rubygems.org/downloads/#{gemfile}"
162
162
  log.info "Searching for remote gem file #{url}"
163
163
  begin
164
- open(url) {|io| expand_and_parse(gemfile, io) }
164
+ # Note: In Ruby 2.4.x, URI.open is a private method. After
165
+ # 2.5, URI.open behaves much like Kernel#open once you've
166
+ # required 'open-uri'
167
+ OpenURI.open_uri(url) {|io| expand_and_parse(gemfile, io) }
165
168
  return true
166
169
  rescue OpenURI::HTTPError
167
170
  nil # noop
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module YARD
3
4
  module CLI
4
5
  # A local documentation server
@@ -58,11 +59,13 @@ module YARD
58
59
 
59
60
  def load_template_paths
60
61
  return if YARD::Config.options[:safe_mode]
62
+
61
63
  Templates::Engine.template_paths |= template_paths
62
64
  end
63
65
 
64
66
  def select_adapter
65
67
  return adapter if adapter
68
+
66
69
  require 'rubygems'
67
70
  require 'rack'
68
71
  self.adapter = YARD::Server::RackAdapter
@@ -129,7 +132,8 @@ module YARD
129
132
  require 'rubygems'
130
133
  YARD::GemIndex.each do |spec|
131
134
  libraries[spec.name] ||= []
132
- libraries[spec.name] |= [YARD::Server::LibraryVersion.new(spec.name, spec.version.to_s, nil, :gem)]
135
+ libraries[spec.name] |= [YARD::Server::LibraryVersion.new(spec.name, spec.version.to_s,
136
+ nil, :gem)]
133
137
  end
134
138
  end
135
139
 
@@ -139,7 +143,8 @@ module YARD
139
143
  if File.exist?("#{gemfile}.lock")
140
144
  Bundler::LockfileParser.new(File.read("#{gemfile}.lock")).specs.each do |spec|
141
145
  libraries[spec.name] ||= []
142
- libraries[spec.name] |= [YARD::Server::LibraryVersion.new(spec.name, spec.version.to_s, nil, :gem)]
146
+ libraries[spec.name] |= [YARD::Server::LibraryVersion.new(spec.name,
147
+ spec.version.to_s, nil, :gem)]
143
148
  end
144
149
  else
145
150
  log.warn "Cannot find #{gemfile}.lock, ignoring --gemfile option"
@@ -171,7 +176,8 @@ module YARD
171
176
  opts.on('-g', '--gems', 'Serves documentation for installed gems') do
172
177
  add_gems
173
178
  end
174
- opts.on('-G', '--gemfile [GEMFILE]', 'Serves documentation for gems from Gemfile') do |gemfile|
179
+ opts.on('-G', '--gemfile [GEMFILE]',
180
+ 'Serves documentation for gems from Gemfile') do |gemfile|
175
181
  add_gems_from_gemfile(gemfile)
176
182
  end
177
183
  opts.on('-t', '--template-path PATH',
@@ -192,23 +198,26 @@ module YARD
192
198
  opts.on('--docroot DOCROOT', 'Uses DOCROOT as document root') do |docroot|
193
199
  server_options[:DocumentRoot] = File.expand_path(docroot)
194
200
  end
195
- opts.on('-a', '--adapter ADAPTER', 'Use the ADAPTER (full Ruby class) for web server') do |adapter|
196
- if adapter.casecmp('webrick') == 0
197
- self.adapter = YARD::Server::WebrickAdapter
198
- elsif adapter.casecmp('rack') == 0
199
- self.adapter = YARD::Server::RackAdapter
200
- else
201
- self.adapter = eval(adapter) # rubocop:disable Lint/Eval
202
- end
201
+ opts.on('-a', '--adapter ADAPTER',
202
+ 'Use the ADAPTER (full Ruby class) for web server') do |adapter|
203
+ self.adapter = if adapter.casecmp('webrick') == 0
204
+ YARD::Server::WebrickAdapter
205
+ elsif adapter.casecmp('rack') == 0
206
+ YARD::Server::RackAdapter
207
+ else
208
+ eval(adapter) # rubocop:disable Security/Eval
209
+ end
203
210
  end
204
- opts.on('-s', '--server TYPE', 'Use a specific server type eg. thin,mongrel,cgi (Rack specific)') do |type|
211
+ opts.on('-s', '--server TYPE',
212
+ 'Use a specific server type eg. thin,mongrel,cgi (Rack specific)') do |type|
205
213
  server_options[:server] = type
206
214
  end
207
215
  opts.on('--fork', 'Use process forking when serving requests') do
208
216
  options[:use_fork] = true
209
217
  end
210
218
  common_options(opts)
211
- opts.on('-e', '--load FILE', 'A Ruby script to load before the source tree is parsed.') do |file|
219
+ opts.on('-e', '--load FILE',
220
+ 'A Ruby script to load before the source tree is parsed.') do |file|
212
221
  scripts << file
213
222
  end
214
223
  parse_options(opts, args)
@@ -145,7 +145,7 @@ module YARD::CodeObjects
145
145
  end
146
146
 
147
147
  # Returns all alias names of the object
148
- # @return [Array<Symbol>] the alias names
148
+ # @return [Array<MethodObject>] the alias names
149
149
  def aliases
150
150
  list = []
151
151
  return list unless namespace.is_a?(NamespaceObject)
@@ -11,6 +11,9 @@ module YARD
11
11
  # Registers a separator with an optional set of valid types that
12
12
  # must follow the separator lexically.
13
13
  #
14
+ # Calls all callbacks defined by {NamespaceMapper.on_invalidate} after
15
+ # the separator is registered.
16
+ #
14
17
  # @param sep [String] the separator string for the namespace
15
18
  # @param valid_types [Array<Symbol>] a list of object types that
16
19
  # must follow the separator. If the list is empty, any type can
@@ -20,6 +23,7 @@ module YARD
20
23
  # register_separator "#", :method
21
24
  # # Anything after a "." denotes a method object
22
25
  # register_separator ".", :method
26
+ # @see .on_invalidate
23
27
  def register_separator(sep, *valid_types)
24
28
  NamespaceMapper.invalidate
25
29
 
@@ -32,6 +36,19 @@ module YARD
32
36
  NamespaceMapper.map[sep] += valid_types
33
37
  end
34
38
 
39
+ # Unregisters a separator by a type.
40
+ #
41
+ # @param type [Symbol] the type to unregister
42
+ # @see #register_separator
43
+ def unregister_separator_by_type(type)
44
+ seps = NamespaceMapper.rev_map[type]
45
+ return unless seps
46
+
47
+ seps.each {|s| NamespaceMapper.map.delete(s) }
48
+ NamespaceMapper.rev_map.delete(type)
49
+ NamespaceMapper.invalidate
50
+ end
51
+
35
52
  # Clears the map of separators.
36
53
  #
37
54
  # @return [void]
@@ -50,6 +67,7 @@ module YARD
50
67
  # default_separator "::"
51
68
  def default_separator(value = nil)
52
69
  if value
70
+ NamespaceMapper.invalidate
53
71
  NamespaceMapper.default_separator = Regexp.quote value
54
72
  else
55
73
  NamespaceMapper.default_separator
@@ -71,17 +89,25 @@ module YARD
71
89
  # @param sep [String] the separator to return types for
72
90
  # @return [Array<Symbol>] a list of types registered to a separator
73
91
  def types_for_separator(sep)
74
- NamespaceMapper.map[sep]
92
+ NamespaceMapper.map[sep] || []
75
93
  end
76
94
 
77
95
  # @param type [String] the type to return separators for
78
96
  # @return [Array<Symbol>] a list of separators registered to a type
79
97
  def separators_for_type(type)
80
- NamespaceMapper.rev_map[type]
98
+ NamespaceMapper.rev_map[type] || []
81
99
  end
82
100
 
83
101
  # Internal methods to act as a singleton registry
84
102
  class << self
103
+ # @!group Invalidation callbacks
104
+
105
+ # Adds a callback that triggers when a new separator is registered or
106
+ # the cache is cleared by invalidation.
107
+ def on_invalidate(&block)
108
+ (@invalidation_callbacks ||= []).push(block)
109
+ end
110
+
85
111
  # @!visibility private
86
112
 
87
113
  # @return [Hash] a mapping of types to separators
@@ -98,11 +124,12 @@ module YARD
98
124
  # @return [void]
99
125
  def invalidate
100
126
  @map_match = nil
127
+ (@invalidation_callbacks || []).each(&:call)
101
128
  end
102
129
 
103
130
  # @return [Regexp] the full list of separators as a regexp match
104
131
  def map_match
105
- @map_match ||= @map.keys.map {|k| Regexp.quote k }.join('|')
132
+ @map_match ||= map.keys.map {|k| Regexp.quote k }.join('|')
106
133
  end
107
134
 
108
135
  # @return [String] the default separator when no separator can begin
@@ -59,7 +59,8 @@ module YARD
59
59
 
60
60
  if @namespace.is_a?(ConstantObject)
61
61
  unless @namespace.value =~ /\A#{NAMESPACEMATCH}\Z/
62
- raise Parser::UndocumentableError, "constant mapping"
62
+ raise Parser::UndocumentableError, "constant mapping for " +
63
+ "#{@origname} (type=#{type.inspect})"
63
64
  end
64
65
 
65
66
  @origname = nil # forget these for a constant
@@ -5,7 +5,7 @@
5
5
  #
6
6
  # @see YARD::CodeObjects::Proxy
7
7
  # @see YARD::Registry.resolve
8
- def P(namespace, name = nil, type = nil) # rubocop:disable Style/MethodName
8
+ def P(namespace, name = nil, type = nil) # rubocop:disable Naming/MethodName
9
9
  if name.nil?
10
10
  name = namespace
11
11
  namespace = nil
@@ -63,6 +63,13 @@ module YARD
63
63
 
64
64
  def namespace_for_variable(var)
65
65
  return namespaces[var] if namespaces[var]
66
+
67
+ # The global variables for Ruby's core error classes does not
68
+ # represent their Ruby name. So we need to look up these names.
69
+ name = ERROR_CLASS_NAMES[var]
70
+ return P(name) if name
71
+
72
+ # Otherwise the name is inferred from the C variable name.
66
73
  var = remove_var_prefix(var)
67
74
  var.empty? ? nil : P(var)
68
75
  end
@@ -120,6 +127,34 @@ module YARD
120
127
 
121
128
  private
122
129
 
130
+ # Generated by update_error_map.rb (Copy+past results)
131
+ ERROR_CLASS_NAMES = {
132
+ 'rb_eArgError' => 'ArgumentError',
133
+ 'rb_eEncodingError' => 'EncodingError',
134
+ 'rb_eException' => 'Exception',
135
+ 'rb_eFatal' => 'fatal',
136
+ 'rb_eFrozenError' => 'FrozenError',
137
+ 'rb_eIndexError' => 'IndexError',
138
+ 'rb_eInterrupt' => 'Interrupt',
139
+ 'rb_eKeyError' => 'KeyError',
140
+ 'rb_eLoadError' => 'LoadError',
141
+ 'rb_eNameError' => 'NameError',
142
+ 'rb_eNoMatchingPatternError' => 'NoMatchingPatternError',
143
+ 'rb_eNoMemError' => 'NoMemoryError',
144
+ 'rb_eNoMethodError' => 'NoMethodError',
145
+ 'rb_eNotImpError' => 'NotImplementedError',
146
+ 'rb_eRangeError' => 'RangeError',
147
+ 'rb_eRuntimeError' => 'RuntimeError',
148
+ 'rb_eScriptError' => 'ScriptError',
149
+ 'rb_eSecurityError' => 'SecurityError',
150
+ 'rb_eSignal' => 'SignalException',
151
+ 'rb_eStandardError' => 'StandardError',
152
+ 'rb_eSyntaxError' => 'SyntaxError',
153
+ 'rb_eSystemCallError' => 'SystemCallError',
154
+ 'rb_eSystemExit' => 'SystemExit',
155
+ 'rb_eTypeError' => 'TypeError',
156
+ }
157
+
123
158
  def remove_var_prefix(var)
124
159
  var.gsub(/^rb_[mc]|^[a-z_]+/, '')
125
160
  end
@@ -2,6 +2,7 @@
2
2
  # Handles the 'include' statement to mixin a module in the instance scope
3
3
  class YARD::Handlers::Ruby::MixinHandler < YARD::Handlers::Ruby::Base
4
4
  handles method_call(:include)
5
+ handles method_call(:prepend)
5
6
  namespace_only
6
7
 
7
8
  process do
@@ -34,7 +35,9 @@ class YARD::Handlers::Ruby::MixinHandler < YARD::Handlers::Ruby::Base
34
35
 
35
36
  rec = recipient(mixin)
36
37
  return if rec.nil? || rec.mixins(scope).include?(obj)
37
- rec.mixins(scope).unshift(obj)
38
+
39
+ shift = statement.method_name(true) == :include ? :unshift : :push
40
+ rec.mixins(scope).send(shift, obj)
38
41
  end
39
42
 
40
43
  def recipient(mixin)
@@ -12,7 +12,7 @@
12
12
 
13
13
  require "irb/notifier"
14
14
 
15
- # :stopdoc:
15
+ # @private
16
16
  module IRB
17
17
  class SLex
18
18
  DOUT = Notifier::def_notifier("SLex::")
@@ -202,8 +202,7 @@ module YARD
202
202
  begin; undef on_#{event}; rescue NameError; end
203
203
  def on_#{event}(tok)
204
204
  unless @last_ns_token == [:kw, "def"] ||
205
- (@tokens.last && @tokens.last[0] == :symbeg) ||
206
- (!@newline && %w(if while until unless).include?(tok))
205
+ (@tokens.last && @tokens.last[0] == :symbeg)
207
206
  (@map[tok] ||= []) << [lineno, charno]
208
207
  end
209
208
  visit_ns_token(:#{event}, tok, true)
@@ -412,7 +411,7 @@ module YARD
412
411
  end
413
412
 
414
413
  def on_dyna_symbol(sym)
415
- rng = if sym.source_range.size == 0 # rubocop:disable Style/ZeroLengthPredicate
414
+ rng = if sym.source_range.to_a.size == 0 # rubocop:disable Style/ZeroLengthPredicate
416
415
  (sym.source_range.begin - 3)...sym.source_range.end
417
416
  else
418
417
  (sym.source_range.begin - 2)..(sym.source_range.end + 1)
@@ -442,6 +441,8 @@ module YARD
442
441
  module_eval(<<-eof, __FILE__, __LINE__ + 1)
443
442
  begin; undef on_#{kw}; rescue NameError; end
444
443
  def on_#{kw}(*args)
444
+ mapping = @map[#{kw.to_s.sub(/_mod$/, '').inspect}]
445
+ mapping.pop if mapping
445
446
  sr = args.last.source_range.first..args.first.source_range.last
446
447
  lr = args.last.line_range.first..args.first.line_range.last
447
448
  #{node_class}.new(:#{kw}, args, :line => lr, :char => sr)
@@ -612,7 +613,7 @@ module YARD
612
613
 
613
614
  def insert_comments
614
615
  root.traverse do |node|
615
- next if %i{comment void_stmt list}.include?(node.type) || node.parent.type != :list
616
+ next if [:comment, :void_stmt, :list].include?(node.type) || node.parent.type != :list
616
617
 
617
618
  # never attach comments to if/unless mod nodes
618
619
  if node.type == :if_mod || node.type == :unless_mod
@@ -684,6 +685,7 @@ module YARD
684
685
  end
685
686
 
686
687
  def freeze_tree(node = nil)
688
+ @tokens = @tokens.sort_by {|t| t.last }
687
689
  nodes = [node || root]
688
690
  until nodes.empty?
689
691
  p_node = nodes.shift
@@ -7,6 +7,7 @@ module YARD
7
7
  # constant or identifier token.
8
8
  class TokenResolver
9
9
  include Enumerable
10
+ include CodeObjects::NamespaceMapper
10
11
 
11
12
  # Creates a token resolver for given source.
12
13
  #
@@ -114,7 +115,8 @@ module YARD
114
115
 
115
116
  if toktype == :const
116
117
  types.any? do |type|
117
- prefix = (type ? type.path : "") + last_sep.to_s
118
+ prefix = type ? type.path : ""
119
+ prefix += last_sep.to_s if separators.include?(last_sep.to_s)
118
120
  self.object = Registry.resolve(@default_namespace, "#{prefix}#{name}", true)
119
121
  end
120
122
  else # ident
@@ -64,7 +64,7 @@ module YARD
64
64
  class SourceParser
65
65
  SHEBANG_LINE = /\A\s*#!\S+/
66
66
  ENCODING_LINE = %r{\A(?:\s*#*!.*\r?\n)?\s*(?:#+|/\*+|//+).*coding\s*[:=]{1,2}\s*([a-z\d_\-]+)}i
67
- FROZEN_STRING_LINE = /frozen(-|_)string(-|_)literal: true/i
67
+ FROZEN_STRING_LINE = /frozen(-|_)string(-|_)literal:\s+(true|false)/i
68
68
 
69
69
  # The default glob of files to be parsed.
70
70
  # @since 0.9.0
@@ -16,6 +16,9 @@ module YARD
16
16
  def initialize(registry = Registry)
17
17
  @registry = registry
18
18
  @default_sep = nil
19
+
20
+ # Preload all code objects for separator declarations
21
+ YARD::CodeObjects.constants.map {|t| YARD::CodeObjects.const_get(t) }
19
22
  end
20
23
 
21
24
  # Performs a lookup on a given path in the registry. Resolution will occur
@@ -186,46 +189,29 @@ module YARD
186
189
  nss
187
190
  end
188
191
 
189
- # @see NamespaceMapper#register_separator
190
- def register_separator(*)
191
- super
192
- invalidate_memoized_matchers
193
- end
194
-
195
- # @see NamespaceMapper#clear_separators
196
- def clear_separators
197
- super
198
- invalidate_memoized_matchers
199
- end
200
-
201
- # @see NamespaceMapper#default_separator
202
- def default_separator(value = nil)
203
- @starts_with_default_separator_match = nil if value
204
- super
205
- end
206
-
207
192
  # @return [Regexp] the regexp match of the default separator
208
193
  def starts_with_default_separator_match
209
- @starts_with_default_separator_match ||= /\A#{default_separator}/
194
+ @@starts_with_default_separator_match ||= /\A#{default_separator}/
210
195
  end
211
196
 
212
197
  # @return [Regexp] the regexp that matches strings starting with
213
198
  # a separator
214
199
  def starts_with_separator_match
215
- @starts_with_separator_match ||= /\A(#{separators_match})/
200
+ @@starts_with_separator_match ||= /\A(#{separators_match})/
216
201
  end
217
202
 
218
203
  # @return [Regexp] the regexp that can be used to split a string on all
219
204
  # occurrences of separator tokens
220
205
  def split_on_separators_match
221
- @split_on_separators_match ||= /(.+?)(#{separators_match}|$)/
206
+ @@split_on_separators_match ||= /(.+?)(#{separators_match}|$)/
222
207
  end
223
208
 
224
209
  # Additional invalidations to done when NamespaceMapper API methods are
225
210
  # called on this class
226
- def invalidate_memoized_matchers
227
- @starts_with_separator_match = nil
228
- @split_on_separators_match = nil
211
+ YARD::CodeObjects::NamespaceMapper.on_invalidate do
212
+ @@starts_with_default_separator_match = nil
213
+ @@starts_with_separator_match = nil
214
+ @@split_on_separators_match = nil
229
215
  end
230
216
  end
231
217
  end
@@ -291,7 +291,7 @@ module YARD
291
291
  def load_checksums
292
292
  return unless File.file?(checksums_path)
293
293
  lines = File.readlines(checksums_path).map do |line|
294
- line.strip.split(/\s+/)
294
+ line.strip.rpartition(' ').tap { |p| p.delete_at(1) }
295
295
  end
296
296
  @checksums = Hash[lines]
297
297
  end
@@ -77,7 +77,7 @@ module YARD
77
77
  p.gsub(/[^\w\.-]/) do |x|
78
78
  encoded = '_'
79
79
 
80
- x.each_byte {|b| encoded << ("%X" % b) }
80
+ x.each_byte {|b| encoded += ("%X" % b) }
81
81
  encoded
82
82
  end
83
83
  end.join('/') + '.' + extension