yard 0.6.8 → 0.7.0

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 (224) hide show
  1. data/.yardopts +1 -0
  2. data/ChangeLog +723 -0
  3. data/README.md +16 -6
  4. data/docs/CodeObjects.md +10 -16
  5. data/docs/GettingStarted.md +232 -32
  6. data/docs/Glossary.md +1 -2
  7. data/docs/Handlers.md +10 -16
  8. data/docs/Overview.md +14 -13
  9. data/docs/Parser.md +13 -22
  10. data/docs/Tags.md +209 -16
  11. data/docs/Templates.md +237 -26
  12. data/docs/WhatsNew.md +178 -2
  13. data/lib/yard.rb +13 -10
  14. data/lib/yard/autoload.rb +22 -18
  15. data/lib/yard/cli/command.rb +13 -12
  16. data/lib/yard/cli/command_parser.rb +20 -19
  17. data/lib/yard/cli/config.rb +19 -19
  18. data/lib/yard/cli/diff.rb +46 -21
  19. data/lib/yard/cli/gems.rb +11 -11
  20. data/lib/yard/cli/graph.rb +13 -13
  21. data/lib/yard/cli/help.rb +1 -1
  22. data/lib/yard/cli/list.rb +22 -0
  23. data/lib/yard/cli/server.rb +17 -17
  24. data/lib/yard/cli/stats.rb +32 -32
  25. data/lib/yard/cli/yardoc.rb +181 -135
  26. data/lib/yard/cli/yri.rb +29 -29
  27. data/lib/yard/code_objects/base.rb +101 -101
  28. data/lib/yard/code_objects/class_object.rb +20 -20
  29. data/lib/yard/code_objects/constant_object.rb +1 -1
  30. data/lib/yard/code_objects/extended_method_object.rb +5 -5
  31. data/lib/yard/code_objects/extra_file_object.rb +89 -0
  32. data/lib/yard/code_objects/macro_object.rb +215 -0
  33. data/lib/yard/code_objects/method_object.rb +30 -30
  34. data/lib/yard/code_objects/module_object.rb +1 -1
  35. data/lib/yard/code_objects/namespace_object.rb +39 -39
  36. data/lib/yard/code_objects/proxy.rb +38 -38
  37. data/lib/yard/code_objects/root_object.rb +1 -1
  38. data/lib/yard/config.rb +40 -40
  39. data/lib/yard/core_ext/array.rb +2 -2
  40. data/lib/yard/core_ext/file.rb +11 -11
  41. data/lib/yard/core_ext/insertion.rb +10 -10
  42. data/lib/yard/core_ext/module.rb +2 -2
  43. data/lib/yard/core_ext/string.rb +2 -2
  44. data/lib/yard/core_ext/symbol_hash.rb +14 -14
  45. data/lib/yard/docstring.rb +122 -54
  46. data/lib/yard/globals.rb +2 -2
  47. data/lib/yard/handlers/base.rb +216 -127
  48. data/lib/yard/handlers/processor.rb +65 -27
  49. data/lib/yard/handlers/ruby/alias_handler.rb +6 -3
  50. data/lib/yard/handlers/ruby/attribute_handler.rb +7 -6
  51. data/lib/yard/handlers/ruby/base.rb +50 -31
  52. data/lib/yard/handlers/ruby/class_condition_handler.rb +11 -11
  53. data/lib/yard/handlers/ruby/class_handler.rb +10 -10
  54. data/lib/yard/handlers/ruby/class_variable_handler.rb +3 -3
  55. data/lib/yard/handlers/ruby/constant_handler.rb +7 -7
  56. data/lib/yard/handlers/ruby/exception_handler.rb +2 -2
  57. data/lib/yard/handlers/ruby/extend_handler.rb +1 -1
  58. data/lib/yard/handlers/ruby/legacy/alias_handler.rb +8 -5
  59. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +6 -5
  60. data/lib/yard/handlers/ruby/legacy/base.rb +42 -27
  61. data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +9 -9
  62. data/lib/yard/handlers/ruby/legacy/class_handler.rb +13 -12
  63. data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +3 -6
  64. data/lib/yard/handlers/ruby/legacy/constant_handler.rb +5 -8
  65. data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -1
  66. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -0
  67. data/lib/yard/handlers/ruby/legacy/macro_handler.rb +40 -0
  68. data/lib/yard/handlers/ruby/legacy/method_handler.rb +10 -10
  69. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +4 -3
  70. data/lib/yard/handlers/ruby/legacy/module_handler.rb +2 -1
  71. data/lib/yard/handlers/ruby/legacy/private_constant_handler.rb +4 -4
  72. data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +2 -1
  73. data/lib/yard/handlers/ruby/legacy/yield_handler.rb +3 -3
  74. data/lib/yard/handlers/ruby/macro_handler.rb +41 -0
  75. data/lib/yard/handlers/ruby/macro_handler_methods.rb +130 -0
  76. data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -1
  77. data/lib/yard/handlers/ruby/method_handler.rb +13 -13
  78. data/lib/yard/handlers/ruby/mixin_handler.rb +4 -4
  79. data/lib/yard/handlers/ruby/module_handler.rb +2 -1
  80. data/lib/yard/handlers/ruby/private_constant_handler.rb +4 -4
  81. data/lib/yard/handlers/ruby/struct_handler_methods.rb +11 -11
  82. data/lib/yard/handlers/ruby/visibility_handler.rb +1 -1
  83. data/lib/yard/handlers/ruby/yield_handler.rb +5 -5
  84. data/lib/yard/logging.rb +11 -11
  85. data/lib/yard/parser/base.rb +8 -8
  86. data/lib/yard/parser/c_parser.rb +42 -33
  87. data/lib/yard/parser/ruby/ast_node.rb +62 -61
  88. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +66 -66
  89. data/lib/yard/parser/ruby/legacy/ruby_parser.rb +4 -4
  90. data/lib/yard/parser/ruby/legacy/statement.rb +11 -11
  91. data/lib/yard/parser/ruby/legacy/statement_list.rb +15 -15
  92. data/lib/yard/parser/ruby/legacy/token_list.rb +9 -9
  93. data/lib/yard/parser/ruby/ruby_parser.rb +51 -37
  94. data/lib/yard/parser/source_parser.rb +271 -46
  95. data/lib/yard/rake/yardoc_task.rb +18 -17
  96. data/lib/yard/registry.rb +64 -64
  97. data/lib/yard/registry_store.rb +34 -34
  98. data/lib/yard/rubygems/backports.rb +8 -0
  99. data/lib/yard/rubygems/backports/LICENSE.txt +57 -0
  100. data/lib/yard/rubygems/backports/MIT.txt +20 -0
  101. data/lib/yard/rubygems/backports/gem.rb +8 -0
  102. data/lib/yard/rubygems/backports/source_index.rb +353 -0
  103. data/lib/yard/rubygems/specification.rb +2 -2
  104. data/lib/yard/serializers/base.rb +20 -20
  105. data/lib/yard/serializers/file_system_serializer.rb +28 -24
  106. data/lib/yard/serializers/process_serializer.rb +3 -3
  107. data/lib/yard/serializers/stdout_serializer.rb +6 -6
  108. data/lib/yard/serializers/yardoc_serializer.rb +17 -17
  109. data/lib/yard/server/adapter.rb +12 -12
  110. data/lib/yard/server/commands/base.rb +26 -26
  111. data/lib/yard/server/commands/display_file_command.rb +3 -2
  112. data/lib/yard/server/commands/display_object_command.rb +5 -5
  113. data/lib/yard/server/commands/frames_command.rb +1 -1
  114. data/lib/yard/server/commands/library_command.rb +7 -7
  115. data/lib/yard/server/commands/library_index_command.rb +2 -2
  116. data/lib/yard/server/commands/list_command.rb +8 -8
  117. data/lib/yard/server/commands/search_command.rb +8 -8
  118. data/lib/yard/server/commands/static_file_command.rb +3 -3
  119. data/lib/yard/server/doc_server_helper.rb +6 -3
  120. data/lib/yard/server/doc_server_serializer.rb +1 -1
  121. data/lib/yard/server/library_version.rb +45 -45
  122. data/lib/yard/server/rack_adapter.rb +10 -10
  123. data/lib/yard/server/router.rb +28 -28
  124. data/lib/yard/server/static_caching.rb +5 -5
  125. data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +3 -3
  126. data/lib/yard/server/templates/default/fulldoc/html/js/live.js +1 -1
  127. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +2 -2
  128. data/lib/yard/server/templates/default/layout/html/headers.erb +13 -8
  129. data/lib/yard/server/templates/default/layout/html/setup.rb +7 -0
  130. data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +2 -2
  131. data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +14 -4
  132. data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +2 -2
  133. data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +2 -2
  134. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +1 -1
  135. data/lib/yard/server/templates/doc_server/search/html/search.erb +1 -1
  136. data/lib/yard/server/webrick_adapter.rb +2 -2
  137. data/lib/yard/tags/default_factory.rb +19 -19
  138. data/lib/yard/tags/default_tag.rb +1 -1
  139. data/lib/yard/tags/library.rb +68 -63
  140. data/lib/yard/tags/option_tag.rb +1 -1
  141. data/lib/yard/tags/overload_tag.rb +9 -9
  142. data/lib/yard/tags/ref_tag_list.rb +2 -2
  143. data/lib/yard/tags/tag.rb +7 -7
  144. data/lib/yard/templates/engine.rb +31 -31
  145. data/lib/yard/templates/erb_cache.rb +1 -1
  146. data/lib/yard/templates/helpers/base_helper.rb +46 -32
  147. data/lib/yard/templates/helpers/filter_helper.rb +2 -2
  148. data/lib/yard/templates/helpers/html_helper.rb +120 -81
  149. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -4
  150. data/lib/yard/templates/helpers/markup/rdoc_markup.rb +9 -9
  151. data/lib/yard/templates/helpers/markup_helper.rb +37 -30
  152. data/lib/yard/templates/helpers/method_helper.rb +7 -7
  153. data/lib/yard/templates/helpers/text_helper.rb +7 -7
  154. data/lib/yard/templates/helpers/uml_helper.rb +3 -3
  155. data/lib/yard/templates/section.rb +14 -14
  156. data/lib/yard/templates/template.rb +54 -54
  157. data/lib/yard/verifier.rb +27 -27
  158. data/spec/cli/list_spec.rb +8 -0
  159. data/spec/cli/yardoc_spec.rb +58 -10
  160. data/spec/code_objects/extra_file_object_spec.rb +132 -0
  161. data/spec/code_objects/macro_object_spec.rb +154 -0
  162. data/spec/docstring_spec.rb +90 -0
  163. data/spec/handlers/base_spec.rb +22 -0
  164. data/spec/handlers/examples/macro_handler_001.rb.txt +73 -0
  165. data/spec/handlers/examples/method_handler_001.rb.txt +17 -0
  166. data/spec/handlers/macro_handler_spec.rb +140 -0
  167. data/spec/handlers/method_handler_spec.rb +28 -0
  168. data/spec/handlers/processor_spec.rb +4 -0
  169. data/spec/handlers/spec_helper.rb +1 -1
  170. data/spec/parser/c_parser_spec.rb +47 -16
  171. data/spec/parser/examples/extrafile.c.txt +8 -0
  172. data/spec/parser/examples/multifile.c.txt +6 -0
  173. data/spec/parser/ruby/ruby_parser_spec.rb +5 -0
  174. data/spec/parser/source_parser_spec.rb +235 -0
  175. data/spec/rake/yardoc_task_spec.rb +22 -17
  176. data/spec/serializers/file_system_serializer_spec.rb +6 -0
  177. data/spec/server/commands/library_command_spec.rb +39 -0
  178. data/spec/spec_helper.rb +14 -0
  179. data/spec/templates/examples/method001.html +6 -6
  180. data/spec/templates/examples/method002.html +4 -4
  181. data/spec/templates/examples/method003.html +10 -10
  182. data/spec/templates/examples/method005.html +2 -2
  183. data/spec/templates/examples/module001.dot +2 -0
  184. data/spec/templates/examples/module001.html +76 -37
  185. data/spec/templates/examples/module001.txt +1 -1
  186. data/spec/templates/helpers/base_helper_spec.rb +7 -2
  187. data/spec/templates/helpers/html_helper_spec.rb +49 -5
  188. data/spec/templates/helpers/markup_helper_spec.rb +9 -8
  189. data/spec/templates/module_spec.rb +7 -0
  190. data/spec/templates/onefile_spec.rb +47 -0
  191. data/templates/default/fulldoc/html/css/style.css +7 -5
  192. data/templates/default/fulldoc/html/full_list.erb +13 -10
  193. data/templates/default/fulldoc/html/full_list_files.erb +1 -1
  194. data/templates/default/fulldoc/html/js/app.js +16 -14
  195. data/templates/default/fulldoc/html/js/full_list.js +7 -6
  196. data/templates/default/fulldoc/html/setup.rb +78 -17
  197. data/templates/default/layout/html/files.erb +1 -1
  198. data/templates/default/layout/html/headers.erb +11 -7
  199. data/templates/default/layout/html/search.erb +4 -4
  200. data/templates/default/layout/html/setup.rb +28 -8
  201. data/templates/default/module/html/inherited_attributes.erb +17 -0
  202. data/templates/default/module/setup.rb +1 -1
  203. data/templates/default/onefile/html/files.erb +2 -2
  204. data/templates/default/onefile/html/layout.erb +1 -1
  205. data/templates/default/onefile/html/setup.rb +7 -5
  206. data/templates/default/tags/html/option.erb +1 -1
  207. data/templates/default/tags/html/tag.erb +3 -3
  208. data/templates/guide/class/html/setup.rb +1 -0
  209. data/templates/guide/docstring/html/setup.rb +1 -0
  210. data/templates/guide/fulldoc/html/css/style.css +91 -0
  211. data/templates/guide/fulldoc/html/js/app.js +33 -0
  212. data/templates/guide/fulldoc/html/setup.rb +54 -0
  213. data/templates/guide/layout/html/layout.erb +81 -0
  214. data/templates/guide/layout/html/setup.rb +24 -0
  215. data/templates/guide/method/html/header.erb +18 -0
  216. data/templates/guide/method/html/setup.rb +21 -0
  217. data/templates/guide/module/html/header.erb +7 -0
  218. data/templates/guide/module/html/method_list.erb +5 -0
  219. data/templates/guide/module/html/setup.rb +26 -0
  220. data/templates/guide/tags/html/setup.rb +8 -0
  221. metadata +40 -7
  222. data/lib/yard/handlers/ruby/legacy/process_handler.rb +0 -13
  223. data/lib/yard/handlers/ruby/process_handler.rb +0 -18
  224. data/spec/handlers/process_handler_spec.rb +0 -17
data/lib/yard/cli/yri.rb CHANGED
@@ -7,26 +7,26 @@ module YARD
7
7
  # The location in {YARD::CONFIG_DIR} where the YRI cache file is loaded
8
8
  # from.
9
9
  CACHE_FILE = File.expand_path('~/.yard/yri_cache')
10
-
10
+
11
11
  # A file containing all paths, delimited by newlines, to search for
12
12
  # yardoc databases.
13
13
  # @since 0.5.1
14
14
  SEARCH_PATHS_FILE = File.expand_path('~/.yard/yri_search_paths')
15
-
15
+
16
16
  # Default search paths that should be loaded dynamically into YRI. These paths
17
17
  # take precedence over all other paths ({SEARCH_PATHS_FILE} and RubyGems
18
- # paths). To add a path, call:
19
- #
18
+ # paths). To add a path, call:
19
+ #
20
20
  # DEFAULT_SEARCH_PATHS.push("/path/to/.yardoc")
21
- #
21
+ #
22
22
  # @return [Array<String>] a list of extra search paths
23
23
  # @since 0.6.0
24
24
  DEFAULT_SEARCH_PATHS = []
25
-
25
+
26
26
  # Helper method to run the utility on an instance.
27
27
  # @see #run
28
28
  def self.run(*args) new.run(*args) end
29
-
29
+
30
30
  def initialize
31
31
  super
32
32
  @cache = {}
@@ -36,25 +36,25 @@ module YARD
36
36
  load_cache
37
37
  @search_paths.uniq!
38
38
  end
39
-
39
+
40
40
  def description
41
41
  "A tool to view documentation in the console like `ri`"
42
42
  end
43
-
43
+
44
44
  # Runs the command-line utility.
45
- #
45
+ #
46
46
  # @example
47
47
  # YRI.new.run('String#reverse')
48
48
  # @param [Array<String>] args each tokenized argument
49
49
  def run(*args)
50
50
  optparse(*args)
51
-
51
+
52
52
  if ::Config::CONFIG['host_os'] =~ /mingw|win32/
53
53
  @serializer ||= YARD::Serializers::StdoutSerializer.new
54
54
  else
55
55
  @serializer ||= YARD::Serializers::ProcessSerializer.new('less')
56
56
  end
57
-
57
+
58
58
  if @name.nil? || @name.strip.empty?
59
59
  print_usage
60
60
  exit(1)
@@ -65,9 +65,9 @@ module YARD
65
65
  exit(1)
66
66
  end
67
67
  end
68
-
68
+
69
69
  protected
70
-
70
+
71
71
  # Prints the command usage
72
72
  # @return [void]
73
73
  # @since 0.5.6
@@ -75,41 +75,41 @@ module YARD
75
75
  puts "Usage: yri [options] <Path to object>"
76
76
  puts "See yri --help for more options."
77
77
  end
78
-
78
+
79
79
  # Caches the .yardoc file where an object can be found in the {CACHE_FILE}
80
80
  # @return [void]
81
81
  def cache_object(name, path)
82
82
  return if path == Registry.yardoc_file
83
83
  @cache[name] = path
84
-
84
+
85
85
  File.open!(CACHE_FILE, 'w') do |file|
86
86
  @cache.each do |key, value|
87
87
  file.puts("#{key} #{value}")
88
88
  end
89
89
  end
90
90
  end
91
-
91
+
92
92
  # @param [CodeObjects::Base] object the object to print.
93
93
  # @return [String] the formatted output for an object.
94
94
  def print_object(object)
95
95
  if object.type == :method && object.is_alias?
96
- tmp = P(object.namespace, (object.scope == :instance ? "#" : "") +
97
- object.namespace.aliases[object].to_s)
96
+ tmp = P(object.namespace, (object.scope == :instance ? "#" : "") +
97
+ object.namespace.aliases[object].to_s)
98
98
  object = tmp unless YARD::CodeObjects::Proxy === tmp
99
99
  end
100
100
  object.format(:serializer => @serializer)
101
101
  end
102
-
102
+
103
103
  # Locates an object by name starting in the cached paths and then
104
104
  # searching through any search paths.
105
- #
105
+ #
106
106
  # @param [String] name the full name of the object
107
107
  # @return [CodeObjects::Base] an object if found
108
108
  # @return [nil] if no object is found
109
109
  def find_object(name)
110
110
  @search_paths.unshift(@cache[name]) if @cache[name]
111
111
  @search_paths.unshift(Registry.yardoc_file)
112
-
112
+
113
113
  log.debug "Searching for #{name} in search paths"
114
114
  @search_paths.each do |path|
115
115
  next unless File.exist?(path)
@@ -123,9 +123,9 @@ module YARD
123
123
  end
124
124
  nil
125
125
  end
126
-
126
+
127
127
  private
128
-
128
+
129
129
  # Loads {CACHE_FILE}
130
130
  # @return [void]
131
131
  def load_cache
@@ -135,7 +135,7 @@ module YARD
135
135
  @cache[line[0]] = line[1]
136
136
  end
137
137
  end
138
-
138
+
139
139
  # Adds all RubyGems yardoc files to search paths
140
140
  # @return [void]
141
141
  def add_gem_paths
@@ -153,7 +153,7 @@ module YARD
153
153
  @search_paths += gem_paths
154
154
  rescue LoadError
155
155
  end
156
-
156
+
157
157
  # Adds paths in {SEARCH_PATHS_FILE}
158
158
  # @since 0.5.1
159
159
  def add_default_paths
@@ -162,7 +162,7 @@ module YARD
162
162
  paths = File.readlines(SEARCH_PATHS_FILE).map {|l| l.strip }
163
163
  @search_paths.push(*paths)
164
164
  end
165
-
165
+
166
166
  # Parses commandline options.
167
167
  # @param [Array<String>] args each tokenized argument
168
168
  def optparse(*args)
@@ -179,11 +179,11 @@ module YARD
179
179
  opts.on('-T', '--no-pager', 'No pager') do
180
180
  @serializer = YARD::Serializers::StdoutSerializer.new
181
181
  end
182
-
182
+
183
183
  opts.on('-p PAGER', '--pager') do |pager|
184
184
  @serializer = YARD::Serializers::ProcessSerializer.new(pager)
185
185
  end
186
-
186
+
187
187
  common_options(opts)
188
188
  parse_options(opts, args)
189
189
  @name = args.first
@@ -4,15 +4,15 @@ module YARD
4
4
  # but also disallows any {Proxy} objects from being added.
5
5
  class CodeObjectList < Array
6
6
  # Creates a new object list associated with a namespace
7
- #
7
+ #
8
8
  # @param [NamespaceObject] owner the namespace the list should be associated with
9
9
  # @return [CodeObjectList]
10
10
  def initialize(owner = Registry.root)
11
11
  @owner = owner
12
12
  end
13
-
13
+
14
14
  # Adds a new value to the list
15
- #
15
+ #
16
16
  # @param [Base] value a code object to add
17
17
  # @return [CodeObjectList] self
18
18
  def push(value)
@@ -26,140 +26,140 @@ module YARD
26
26
  end
27
27
  alias_method :<<, :push
28
28
  end
29
-
30
-
29
+
30
+
31
31
  # Namespace separator
32
32
  NSEP = '::'
33
-
33
+
34
34
  # Regex-quoted namespace separator
35
35
  NSEPQ = NSEP
36
-
36
+
37
37
  # Instance method separator
38
38
  ISEP = '#'
39
39
 
40
40
  # Regex-quoted instance method separator
41
41
  ISEPQ = ISEP
42
-
42
+
43
43
  # Class method separator
44
44
  CSEP = '.'
45
-
45
+
46
46
  # Regex-quoted class method separator
47
47
  CSEPQ = Regexp.quote CSEP
48
-
48
+
49
49
  # Regular expression to match constant name
50
50
  CONSTANTMATCH = /[A-Z]\w*/
51
-
51
+
52
52
  # Regular expression to match namespaces (const A or complex path A::B)
53
53
  NAMESPACEMATCH = /(?:(?:#{NSEPQ})?#{CONSTANTMATCH})+/
54
-
54
+
55
55
  # Regular expression to match a method name
56
56
  METHODNAMEMATCH = /[a-zA-Z_]\w*[!?=]?|[-+~]\@|<<|>>|=~|===?|<=>|[<>]=?|\*\*|[-\/+%^&*~`|]|\[\]=?/
57
-
57
+
58
58
  # Regular expression to match a fully qualified method def (self.foo, Class.foo).
59
59
  METHODMATCH = /(?:(?:#{NAMESPACEMATCH}|[a-z]\w*)\s*(?:#{CSEPQ}|#{NSEPQ})\s*)?#{METHODNAMEMATCH}/
60
-
60
+
61
61
  # All builtin Ruby exception classes for inheritance tree.
62
- BUILTIN_EXCEPTIONS = ["SecurityError", "Exception", "NoMethodError", "FloatDomainError",
63
- "IOError", "TypeError", "NotImplementedError", "SystemExit", "Interrupt", "SyntaxError",
64
- "RangeError", "NoMemoryError", "ArgumentError", "ThreadError", "EOFError", "RuntimeError",
65
- "ZeroDivisionError", "StandardError", "LoadError", "NameError", "LocalJumpError", "SystemCallError",
62
+ BUILTIN_EXCEPTIONS = ["SecurityError", "Exception", "NoMethodError", "FloatDomainError",
63
+ "IOError", "TypeError", "NotImplementedError", "SystemExit", "Interrupt", "SyntaxError",
64
+ "RangeError", "NoMemoryError", "ArgumentError", "ThreadError", "EOFError", "RuntimeError",
65
+ "ZeroDivisionError", "StandardError", "LoadError", "NameError", "LocalJumpError", "SystemCallError",
66
66
  "SignalException", "ScriptError", "SystemStackError", "RegexpError", "IndexError"]
67
67
  # All builtin Ruby classes for inheritance tree.
68
68
  # @note MatchingData is a 1.8.x legacy class
69
- BUILTIN_CLASSES = ["TrueClass", "Array", "Dir", "Struct", "UnboundMethod", "Object", "Fixnum", "Float",
70
- "ThreadGroup", "MatchingData", "MatchData", "Proc", "Binding", "Class", "Time", "Bignum", "NilClass", "Symbol",
71
- "Numeric", "String", "Data", "MatchData", "Regexp", "Integer", "File", "IO", "Range", "FalseClass",
69
+ BUILTIN_CLASSES = ["TrueClass", "Array", "Dir", "Struct", "UnboundMethod", "Object", "Fixnum", "Float",
70
+ "ThreadGroup", "MatchingData", "MatchData", "Proc", "Binding", "Class", "Time", "Bignum", "NilClass", "Symbol",
71
+ "Numeric", "String", "Data", "MatchData", "Regexp", "Integer", "File", "IO", "Range", "FalseClass",
72
72
  "Method", "Continuation", "Thread", "Hash", "Module"] + BUILTIN_EXCEPTIONS
73
73
  # All builtin Ruby modules for mixin handling.
74
- BUILTIN_MODULES = ["ObjectSpace", "Signal", "Marshal", "Kernel", "Process", "GC", "FileTest", "Enumerable",
74
+ BUILTIN_MODULES = ["ObjectSpace", "Signal", "Marshal", "Kernel", "Process", "GC", "FileTest", "Enumerable",
75
75
  "Comparable", "Errno", "Precision", "Math"]
76
76
  # All builtin Ruby classes and modules.
77
77
  BUILTIN_ALL = BUILTIN_CLASSES + BUILTIN_MODULES
78
-
78
+
79
79
  # Hash of {BUILTIN_EXCEPTIONS} as keys and true as value (for O(1) lookups)
80
80
  BUILTIN_EXCEPTIONS_HASH = BUILTIN_EXCEPTIONS.inject({}) {|h,n| h.update(n => true) }
81
-
81
+
82
82
  # +Base+ is the superclass of all code objects recognized by YARD. A code
83
- # object is any entity in the Ruby language (class, method, module). A
83
+ # object is any entity in the Ruby language (class, method, module). A
84
84
  # DSL might subclass +Base+ to create a new custom object representing
85
- # a new entity type.
86
- #
85
+ # a new entity type.
86
+ #
87
87
  # == Registry Integration
88
- # Any created object associated with a namespace is immediately registered
88
+ # Any created object associated with a namespace is immediately registered
89
89
  # with the registry. This allows the Registry to act as an identity map
90
90
  # to ensure that no object is represented by more than one Ruby object
91
91
  # in memory. A unique {#path} is essential for this identity map to work
92
92
  # correctly.
93
- #
93
+ #
94
94
  # == Custom Attributes
95
95
  # Code objects allow arbitrary custom attributes to be set using the
96
96
  # {#[]=} assignment method.
97
- #
97
+ #
98
98
  # == Namespaces
99
99
  # There is a special type of object called a "namespace". These are subclasses
100
100
  # of the {NamespaceObject} and represent Ruby entities that can have
101
101
  # objects defined within them. Classically these are modules and classes,
102
- # though a DSL might create a custom {NamespaceObject} to describe a
102
+ # though a DSL might create a custom {NamespaceObject} to describe a
103
103
  # specific set of objects.
104
- #
104
+ #
105
105
  # @abstract This class should not be used directly. Instead, create a
106
106
  # subclass that implements {#path}, {#sep} or {#type}.
107
107
  # @see Registry
108
108
  # @see #path
109
109
  # @see #[]=
110
110
  # @see NamespaceObject
111
- class Base
111
+ class Base
112
112
  # The files the object was defined in. To add a file, use {#add_file}.
113
113
  # @return [Array<String>] a list of files
114
114
  # @see #add_file
115
115
  attr_reader :files
116
-
116
+
117
117
  # The namespace the object is defined in. If the object is in the
118
118
  # top level namespace, this is {Registry.root}
119
119
  # @return [NamespaceObject] the namespace object
120
120
  attr_reader :namespace
121
-
121
+
122
122
  # The source code associated with the object
123
123
  # @return [String, nil] source, if present, or nil
124
124
  attr_reader :source
125
-
125
+
126
126
  # Language of the source code associated with the object. Defaults to
127
127
  # +:ruby+.
128
- #
128
+ #
129
129
  # @return [Symbol] the language type
130
130
  attr_accessor :source_type
131
-
131
+
132
132
  # The one line signature representing an object. For a method, this will
133
133
  # be of the form "def meth(arguments...)". This is usually the first
134
134
  # source line.
135
- #
135
+ #
136
136
  # @return [String] a line of source
137
137
  attr_accessor :signature
138
-
138
+
139
139
  # The documentation string associated with the object
140
140
  # @return [Docstring] the documentation string
141
141
  attr_reader :docstring
142
-
142
+
143
143
  # Marks whether or not the method is conditionally defined at runtime
144
144
  # @return [Boolean] true if the method is conditionally defined at runtime
145
145
  attr_accessor :dynamic
146
-
146
+
147
147
  # @return [String] the group this object is associated with
148
148
  # @since 0.6.0
149
149
  attr_accessor :group
150
-
150
+
151
151
  # Is the object defined conditionally at runtime?
152
152
  # @see #dynamic
153
153
  def dynamic?; @dynamic end
154
-
154
+
155
155
  # @return [Symbol] the visibility of an object (:public, :private, :protected)
156
156
  attr_accessor :visibility
157
157
  undef visibility=
158
158
  def visibility=(v) @visibility = v.to_sym end
159
-
159
+
160
160
  class << self
161
161
  # Allocates a new code object
162
- # @return [Base]
162
+ # @return [Base]
163
163
  # @see #initialize
164
164
  def new(namespace, name, *args, &block)
165
165
  raise ArgumentError, "invalid empty object name" if name.to_s.empty?
@@ -170,28 +170,28 @@ module YARD
170
170
  if name.to_s[0,2] == NSEP
171
171
  name = name.to_s[2..-1]
172
172
  namespace = Registry.root
173
- elsif name =~ /(?:#{NSEPQ}|#{ISEPQ}|#{CSEPQ})([^#{NSEPQ}#{ISEPQ}#{CSEPQ}]+)$/
173
+ elsif name =~ /(?:#{NSEPQ})([^:]+)$/
174
174
  return new(Proxy.new(namespace, $`), $1, *args, &block)
175
175
  end
176
-
176
+
177
177
  obj = super(namespace, name, *args)
178
178
  existing_obj = Registry.at(obj.path)
179
179
  obj = existing_obj if existing_obj && existing_obj.class == self
180
180
  yield(obj) if block_given?
181
181
  obj
182
182
  end
183
-
183
+
184
184
  # Compares the class with subclasses
185
- #
185
+ #
186
186
  # @param [Object] other the other object to compare classes with
187
187
  # @return [Boolean] true if other is a subclass of self
188
188
  def ===(other)
189
189
  other.is_a?(self)
190
190
  end
191
191
  end
192
-
192
+
193
193
  # Creates a new code object
194
- #
194
+ #
195
195
  # @example Create a method in the root namespace
196
196
  # CodeObjects::Base.new(:root, '#method') # => #<yardoc method #method>
197
197
  # @example Create class Z inside namespace X::Y
@@ -200,12 +200,12 @@ module YARD
200
200
  # @param [NamespaceObject] namespace the namespace the object belongs in,
201
201
  # {Registry.root} or :root should be provided if it is associated with
202
202
  # the top level namespace.
203
- # @param [Symbol, String] name the name (or complex path) of the object.
203
+ # @param [Symbol, String] name the name (or complex path) of the object.
204
204
  # @yield [self] a block to perform any extra initialization on the object
205
205
  # @yieldparam [Base] self the newly initialized code object
206
206
  # @return [Base] the newly created object
207
207
  def initialize(namespace, name, *args, &block)
208
- if namespace && namespace != :root &&
208
+ if namespace && namespace != :root &&
209
209
  !namespace.is_a?(NamespaceObject) && !namespace.is_a?(Proxy)
210
210
  raise ArgumentError, "Invalid namespace object: #{namespace}"
211
211
  end
@@ -221,20 +221,20 @@ module YARD
221
221
  self.namespace = namespace
222
222
  yield(self) if block_given?
223
223
  end
224
-
224
+
225
225
  # The name of the object
226
226
  # @param [Boolean] prefix whether to show a prefix. Implement
227
227
  # this in a subclass to define how the prefix is showed.
228
228
  # @return [Symbol] if prefix is false, the symbolized name
229
- # @return [String] if prefix is true, prefix + the name as a String.
229
+ # @return [String] if prefix is true, prefix + the name as a String.
230
230
  # This must be implemented by the subclass.
231
231
  def name(prefix = false)
232
232
  prefix ? @name.to_s : @name
233
233
  end
234
-
234
+
235
235
  # Associates a file with a code object, optionally adding the line where it was defined.
236
236
  # By convention, '<stdin>' should be used to associate code that comes form standard input.
237
- #
237
+ #
238
238
  # @param [String] file the filename ('<stdin>' for standard input)
239
239
  # @param [Fixnum, nil] line the line number where the object lies in the file
240
240
  # @param [Boolean] has_comments whether or not the definition has comments associated. This
@@ -246,28 +246,28 @@ module YARD
246
246
  return if files.include?(obj)
247
247
  if has_comments && !@current_file_has_comments
248
248
  @current_file_has_comments = true
249
- @files.unshift(obj)
249
+ @files.unshift(obj)
250
250
  else
251
251
  @files << obj # back of the line
252
252
  end
253
253
  end
254
-
254
+
255
255
  # Returns the filename the object was first parsed at, taking
256
256
  # definitions with docstrings first.
257
- #
257
+ #
258
258
  # @return [String] a filename
259
259
  def file
260
260
  @files.first ? @files.first[0] : nil
261
261
  end
262
262
 
263
263
  # Returns the line the object was first parsed at (or nil)
264
- #
264
+ #
265
265
  # @return [Fixnum] the line where the object was first defined.
266
266
  # @return [nil] if there is no line associated with the object
267
267
  def line
268
268
  @files.first ? @files.first[1] : nil
269
269
  end
270
-
270
+
271
271
  # Tests if another object is equal to this, including a proxy
272
272
  # @param [Base, Proxy] other if other is a {Proxy}, tests if
273
273
  # the paths are equal
@@ -281,7 +281,7 @@ module YARD
281
281
  end
282
282
  alias == equal?
283
283
  alias eql? equal?
284
-
284
+
285
285
  # @return [Integer] the object's hash value (for equality checking)
286
286
  def hash; path.hash end
287
287
 
@@ -296,11 +296,11 @@ module YARD
296
296
  instance_variable_get("@#{key}")
297
297
  end
298
298
  end
299
-
299
+
300
300
  # Sets a custom attribute on the object
301
301
  # @param [#to_s] key the name of the custom attribute
302
302
  # @param [Object] value the value to associate
303
- # @return [void]
303
+ # @return [void]
304
304
  # @see #[]
305
305
  def []=(key, value)
306
306
  if respond_to?("#{key}=")
@@ -309,7 +309,7 @@ module YARD
309
309
  instance_variable_set("@#{key}", value)
310
310
  end
311
311
  end
312
-
312
+
313
313
  # @overload dynamic_attr_name
314
314
  # @return the value of attribute named by the method attribute name
315
315
  # @raise [NoMethodError] if no method or custom attribute exists by
@@ -331,8 +331,8 @@ module YARD
331
331
 
332
332
  # Attaches source code to a code object with an optional file location
333
333
  #
334
- # @param [#source, String] statement
335
- # the +Parser::Statement+ holding the source code or the raw source
334
+ # @param [#source, String] statement
335
+ # the +Parser::Statement+ holding the source code or the raw source
336
336
  # as a +String+ for the definition of the code object only (not the block)
337
337
  def source=(statement)
338
338
  if statement.respond_to?(:source)
@@ -343,49 +343,49 @@ module YARD
343
343
  @source = format_source(statement.to_s)
344
344
  end
345
345
  end
346
-
346
+
347
347
  def docstring
348
- value = case @docstring
348
+ return @docstring if !@docstring_extra
349
+ case @docstring
349
350
  when Proxy
350
- Docstring.new("", self)
351
+ return @docstring_extra
351
352
  when Base
352
- @docstring.docstring
353
- else
354
- @docstring
353
+ @docstring = @docstring.docstring + @docstring_extra
354
+ @docstring_extra = nil
355
355
  end
356
- @docstring_extra ? value + @docstring_extra : value
356
+ @docstring
357
357
  end
358
358
 
359
359
  # Attaches a docstring to a code object by parsing the comments attached to the statement
360
360
  # and filling the {#tags} and {#docstring} methods with the parsed information.
361
361
  #
362
- # @param [String, Array<String>, Docstring] comments
363
- # the comments attached to the code object to be parsed
362
+ # @param [String, Array<String>, Docstring] comments
363
+ # the comments attached to the code object to be parsed
364
364
  # into a docstring and meta tags.
365
365
  def docstring=(comments)
366
366
  if comments =~ /\A\s*\(see (\S+)\s*\)(?:\s|$)/
367
367
  path, extra = $1, $'
368
- @docstring_extra = extra.empty? ? nil : Docstring.new(extra, self)
368
+ @docstring_extra = Docstring.new(extra, self)
369
369
  @docstring = Proxy.new(namespace, path)
370
370
  else
371
371
  @docstring_extra = nil
372
372
  @docstring = Docstring === comments ? comments : Docstring.new(comments, self)
373
373
  end
374
374
  end
375
-
375
+
376
376
  # Default type is the lowercase class name without the "Object" suffix.
377
377
  # Override this method to provide a custom object type
378
- #
378
+ #
379
379
  # @return [Symbol] the type of code object this represents
380
380
  def type
381
381
  self.class.name.split(/#{NSEPQ}/).last.gsub(/Object$/, '').downcase.to_sym
382
382
  end
383
-
383
+
384
384
  # Represents the unique path of the object. The default implementation
385
385
  # joins the path of {#namespace} with {#name} via the value of {#sep}.
386
- # Custom code objects should ensure that the path is unique to the code
386
+ # Custom code objects should ensure that the path is unique to the code
387
387
  # object by either overriding {#sep} or this method.
388
- #
388
+ #
389
389
  # @example The path of an instance method
390
390
  # MethodObject.new(P("A::B"), :c).path # => "A::B#c"
391
391
  # @return [String] the unique path of the object
@@ -398,7 +398,7 @@ module YARD
398
398
  end
399
399
  end
400
400
  alias_method :to_s, :path
401
-
401
+
402
402
  # @param [Base, String] other another code object (or object path)
403
403
  # @return [String] the shortest relative path from this object to +other+
404
404
  # @since 0.5.3
@@ -421,9 +421,9 @@ module YARD
421
421
  result = other.sub(/^#{Regexp.quote common}#{suffix}/, '')
422
422
  result.empty? ? other : result
423
423
  end
424
-
424
+
425
425
  # Renders the object using the {Templates::Engine templating system}.
426
- #
426
+ #
427
427
  # @example Formats a class in plaintext
428
428
  # puts P('MyClass').format
429
429
  # @example Formats a method in html with rdoc markup
@@ -439,26 +439,26 @@ module YARD
439
439
  options.merge!(:object => self)
440
440
  Templates::Engine.render(options)
441
441
  end
442
-
442
+
443
443
  # Inspects the object, returning the type and path
444
444
  # @return [String] a string describing the object
445
445
  def inspect
446
446
  "#<yardoc #{type} #{path}>"
447
447
  end
448
-
448
+
449
449
  # Sets the namespace the object is defined in.
450
- #
451
- # @param [NamespaceObject, :root, nil] obj the new namespace (:root
450
+ #
451
+ # @param [NamespaceObject, :root, nil] obj the new namespace (:root
452
452
  # for {Registry.root}). If obj is nil, the object is unregistered
453
453
  # from the Registry.
454
454
  def namespace=(obj)
455
455
  if @namespace
456
- @namespace.children.delete(self)
456
+ @namespace.children.delete(self)
457
457
  Registry.delete(self)
458
458
  end
459
-
459
+
460
460
  @namespace = (obj == :root ? Registry.root : obj)
461
-
461
+
462
462
  if @namespace
463
463
  reg_obj = Registry.at(path)
464
464
  return if reg_obj && reg_obj.class == self.class
@@ -466,38 +466,38 @@ module YARD
466
466
  Registry.register(self)
467
467
  end
468
468
  end
469
-
469
+
470
470
  alias_method :parent, :namespace
471
471
  alias_method :parent=, :namespace=
472
472
 
473
473
  # Gets a tag from the {#docstring}
474
474
  # @see Docstring#tag
475
475
  def tag(name); docstring.tag(name) end
476
-
476
+
477
477
  # Gets a list of tags from the {#docstring}
478
478
  # @see Docstring#tags
479
479
  def tags(name = nil); docstring.tags(name) end
480
-
480
+
481
481
  # Tests if the {#docstring} has a tag
482
482
  # @see Docstring#has_tag?
483
483
  def has_tag?(name); docstring.has_tag?(name) end
484
-
484
+
485
485
  # @return whether or not this object is a RootObject
486
486
  def root?; false end
487
487
 
488
488
  protected
489
-
489
+
490
490
  # Override this method with a custom component separator. For instance,
491
491
  # {MethodObject} implements sep as '#' or '.' (depending on if the
492
492
  # method is instance or class respectively). {#path} depends on this
493
493
  # value to generate the full path in the form: namespace.path + sep + name
494
- #
494
+ #
495
495
  # @return [String] the component that separates the namespace path
496
496
  # and the name (default is {NSEP})
497
497
  def sep; NSEP end
498
498
 
499
499
  # Formats source code by removing leading indentation
500
- #
500
+ #
501
501
  # @param [String] source the source code to format
502
502
  # @return [String] formatted source
503
503
  def format_source(source)