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
@@ -3,38 +3,38 @@ require 'rake/tasklib'
3
3
 
4
4
  module YARD
5
5
  module Rake
6
-
6
+
7
7
  # The rake task to run {CLI::Yardoc} and generate documentation.
8
8
  class YardocTask < ::Rake::TaskLib
9
9
  # The name of the task
10
10
  # @return [String] the task name
11
11
  attr_accessor :name
12
-
12
+
13
13
  # Options to pass to {CLI::Yardoc}
14
14
  # @return [Hash] the options passed to the commandline utility
15
15
  attr_accessor :options
16
-
16
+
17
17
  # The Ruby source files (and any extra documentation files separated by '-')
18
18
  # to process
19
19
  # @return [Array<String>] a list of files
20
20
  attr_accessor :files
21
-
21
+
22
22
  # Runs a +Proc+ before the task
23
23
  # @return [Proc] a proc to call before running the task
24
24
  attr_accessor :before
25
-
25
+
26
26
  # Runs a +Proc+ after the task
27
27
  # @return [Proc] a proc to call after running the task
28
28
  attr_accessor :after
29
-
30
- # @return [Proc] an optional lambda to run against all objects being
31
- # generated. Any object that the lambda returns false for will be
32
- # excluded from documentation.
29
+
30
+ # @return [Verifier, Proc] an optional {Verifier} to run against all objects
31
+ # being generated. Any object that the verifier returns false for will be
32
+ # excluded from documentation. This attribute can also be a lambda.
33
33
  # @see Verifier
34
34
  attr_accessor :verifier
35
35
 
36
36
  # Creates a new task with name +name+.
37
- #
37
+ #
38
38
  # @param [String, Symbol] name the name of the rake task
39
39
  # @yield a block to allow any options to be modified on the task
40
40
  # @yieldparam [YardocTask] _self the task object to allow any parameters
@@ -43,25 +43,26 @@ module YARD
43
43
  @name = name
44
44
  @options = []
45
45
  @files = []
46
-
46
+
47
47
  yield self if block_given?
48
- self.options += ENV['OPTS'].split(/[ ,]/) if ENV['OPTS']
48
+ self.options += ENV['OPTS'].split(/[ ,]/) if ENV['OPTS']
49
49
  self.files += ENV['FILES'].split(/[ ,]/) if ENV['FILES']
50
-
50
+
51
51
  define
52
52
  end
53
-
53
+
54
54
  protected
55
-
55
+
56
56
  # Defines the rake task
57
- # @return [void]
57
+ # @return [void]
58
58
  def define
59
59
  desc "Generate YARD Documentation"
60
60
  task(name) do
61
61
  before.call if before.is_a?(Proc)
62
62
  yardoc = YARD::CLI::Yardoc.new
63
+ yardoc.parse_arguments *(options + files)
63
64
  yardoc.options[:verifier] = verifier if verifier
64
- yardoc.run *(options + files)
65
+ yardoc.run
65
66
  after.call if after.is_a?(Proc)
66
67
  end
67
68
  end
data/lib/yard/registry.rb CHANGED
@@ -5,21 +5,21 @@ module YARD
5
5
  # The +Registry+ is the centralized data store for all {CodeObjects} created
6
6
  # during parsing. The storage is a key value store with the object's path
7
7
  # (see {CodeObjects::Base#path}) as the key and the object itself as the value.
8
- # Object paths must be unique to be stored in the Registry. All lookups for
9
- # objects are done on the singleton Registry instance using the {Registry.at}
8
+ # Object paths must be unique to be stored in the Registry. All lookups for
9
+ # objects are done on the singleton Registry instance using the {Registry.at}
10
10
  # or {Registry.resolve} methods.
11
- #
12
- # == Saving / Loading a Registry
13
- # The registry is saved to a "yardoc file" (actually a directory), which can
14
- # be loaded back to perform any lookups. See {Registry.load!} and
11
+ #
12
+ # == Saving / Loading a Registry
13
+ # The registry is saved to a "yardoc file" (actually a directory), which can
14
+ # be loaded back to perform any lookups. See {Registry.load!} and
15
15
  # {Registry.save} for information on saving and loading of a yardoc file.
16
- #
16
+ #
17
17
  # == Threading Notes
18
18
  # The registry class is a singleton class that is accessed directly in many
19
19
  # places across YARD. To mitigate threading issues, YARD (0.6.5+) makes
20
20
  # the Registry thread local. This means all access to a registry for a specific
21
21
  # object set must occur in the originating thread.
22
- #
22
+ #
23
23
  # @example Loading a Registry
24
24
  # Registry.load!('/path/to/yardocfile') # loads all objects into memory
25
25
  # Registry.at('YARD::CodeObjects::Base').docstring
@@ -37,13 +37,13 @@ module YARD
37
37
  # @group Getting .yardoc File Locations
38
38
 
39
39
  # Returns the .yardoc file associated with a gem.
40
- #
40
+ #
41
41
  # @param [String] gem the name of the gem to search for
42
42
  # @param [String] ver_require an optional Gem version requirement
43
43
  # @param [Boolean] for_writing whether or not the method should search
44
44
  # for writable locations
45
- # @return [String] if +for_writing+ is set to +true+, returns the best
46
- # location suitable to write the .yardoc file. Otherwise, the first
45
+ # @return [String] if +for_writing+ is set to +true+, returns the best
46
+ # location suitable to write the .yardoc file. Otherwise, the first
47
47
  # existing location associated with the gem's .yardoc file.
48
48
  # @return [nil] if +for_writing+ is set to false and no yardoc file
49
49
  # is found, returns nil.
@@ -51,12 +51,12 @@ module YARD
51
51
  spec = Gem.source_index.find_name(gem, ver_require)
52
52
  return if spec.empty?
53
53
  spec = spec.first
54
-
54
+
55
55
  if gem =~ /^yard-doc-/
56
56
  path = File.join(spec.full_gem_path, DEFAULT_YARDOC_FILE)
57
57
  return File.exist?(path) && !for_writing ? path : nil
58
58
  end
59
-
59
+
60
60
  if for_writing
61
61
  global_yardoc_file(spec, for_writing) ||
62
62
  local_yardoc_file(spec, for_writing)
@@ -65,20 +65,20 @@ module YARD
65
65
  global_yardoc_file(spec, for_writing)
66
66
  end
67
67
  end
68
-
68
+
69
69
  # Gets/sets the yardoc filename
70
70
  # @return [String] the yardoc filename
71
71
  # @see DEFAULT_YARDOC_FILE
72
72
  attr_accessor :yardoc_file
73
73
  def yardoc_file=(v) Thread.current[:__yard_yardoc_file__] = v end
74
74
  def yardoc_file
75
- Thread.current[:__yard_yardoc_file__] ||= DEFAULT_YARDOC_FILE
75
+ Thread.current[:__yard_yardoc_file__] ||= DEFAULT_YARDOC_FILE
76
76
  end
77
-
77
+
78
78
  # @group Loading Data from Disk
79
-
79
+
80
80
  # Loads the registry and/or parses a list of files
81
- #
81
+ #
82
82
  # @example Loads the yardoc file or parses files 'a', 'b' and 'c' (but not both)
83
83
  # Registry.load(['a', 'b', 'c'])
84
84
  # @example Reparses files 'a' and 'b' regardless of whether yardoc file exists
@@ -108,9 +108,9 @@ module YARD
108
108
  end
109
109
  self
110
110
  end
111
-
111
+
112
112
  # Loads a yardoc file directly
113
- #
113
+ #
114
114
  # @param [String] file the yardoc file to load.
115
115
  # @return [Registry] the registry object (for chaining)
116
116
  def load_yardoc(file = yardoc_file)
@@ -118,10 +118,10 @@ module YARD
118
118
  thread_local_store.load(file)
119
119
  self
120
120
  end
121
-
121
+
122
122
  # Loads a yardoc file and forces all objects cached on disk into
123
123
  # memory. Equivalent to calling {load_yardoc} followed by {load_all}
124
- #
124
+ #
125
125
  # @param [String] file the yardoc file to load
126
126
  # @return [Registry] the registry object (for chaining)
127
127
  # @see #load_yardoc
@@ -132,9 +132,9 @@ module YARD
132
132
  thread_local_store.load!(file)
133
133
  self
134
134
  end
135
-
135
+
136
136
  # Forces all objects cached on disk into memory
137
- #
137
+ #
138
138
  # @example Loads all objects from disk
139
139
  # Registry.load
140
140
  # Registry.all.count #=> 0
@@ -146,86 +146,86 @@ module YARD
146
146
  thread_local_store.load_all
147
147
  self
148
148
  end
149
-
149
+
150
150
  # @group Saving and Deleting Data from Disk
151
151
 
152
152
  # Saves the registry to +file+
153
- #
153
+ #
154
154
  # @param [String] file the yardoc file to save to
155
155
  # @return [Boolean] true if the file was saved
156
156
  def save(merge = false, file = yardoc_file)
157
157
  thread_local_store.save(merge, file)
158
158
  end
159
-
159
+
160
160
  # Deletes the yardoc file from disk
161
161
  # @return [void]
162
162
  def delete_from_disk
163
163
  thread_local_store.destroy
164
164
  end
165
-
165
+
166
166
  # @group Adding and Deleting Objects from the Registry
167
167
 
168
168
  # Registers a new object with the registry
169
- #
169
+ #
170
170
  # @param [CodeObjects::Base] object the object to register
171
171
  # @return [CodeObjects::Base] the registered object
172
172
  def register(object)
173
173
  return if object.is_a?(CodeObjects::Proxy)
174
174
  thread_local_store[object.path] = object
175
175
  end
176
-
176
+
177
177
  # Deletes an object from the registry
178
178
  # @param [CodeObjects::Base] object the object to remove
179
- # @return [void]
180
- def delete(object)
179
+ # @return [void]
180
+ def delete(object)
181
181
  thread_local_store.delete(object.path)
182
182
  end
183
183
 
184
184
  # Clears the registry
185
- # @return [void]
185
+ # @return [void]
186
186
  def clear
187
187
  self.thread_local_store = RegistryStore.new
188
188
  end
189
189
 
190
190
  # @group Accessing Objects in the Registry
191
-
191
+
192
192
  # Iterates over {all} with no arguments
193
193
  def each(&block)
194
194
  all.each(&block)
195
195
  end
196
-
196
+
197
197
  # Returns all objects in the registry that match one of the types provided
198
198
  # in the +types+ list (if +types+ is provided).
199
- #
199
+ #
200
200
  # @example Returns all objects
201
201
  # Registry.all
202
202
  # @example Returns all classes and modules
203
203
  # Registry.all(:class, :module)
204
204
  # @param [Array<Symbol>] types an optional list of types to narrow the
205
- # objects down by. Equivalent to performing a select:
205
+ # objects down by. Equivalent to performing a select:
206
206
  # +Registry.all.select {|o| types.include(o.type) }+
207
207
  # @return [Array<CodeObjects::Base>] the list of objects found
208
208
  # @see CodeObjects::Base#type
209
209
  def all(*types)
210
- thread_local_store.values.select do |obj|
210
+ thread_local_store.values.select do |obj|
211
211
  if types.empty?
212
212
  obj != root
213
213
  else
214
214
  obj != root &&
215
- types.any? do |type|
215
+ types.any? do |type|
216
216
  type.is_a?(Symbol) ? obj.type == type : obj.is_a?(type)
217
217
  end
218
218
  end
219
219
  end + (types.include?(:root) ? [root] : [])
220
220
  end
221
-
221
+
222
222
  # Returns the paths of all of the objects in the registry.
223
223
  # @param [Boolean] reload whether to load entire database
224
224
  # @return [Array<String>] all of the paths in the registry.
225
225
  def paths(reload = false)
226
226
  thread_local_store.keys(reload).map {|k| k.to_s }
227
227
  end
228
-
228
+
229
229
  # Returns the object at a specific path.
230
230
  # @param [String, :root] path the pathname to look for. If +path+ is +root+,
231
231
  # returns the {root} object.
@@ -233,14 +233,14 @@ module YARD
233
233
  # @return [nil] if no object is found
234
234
  def at(path) path ? thread_local_store[path] : nil end
235
235
  alias_method :[], :at
236
-
236
+
237
237
  # The root namespace object.
238
238
  # @return [CodeObjects::RootObject] the root object in the namespace
239
239
  def root; thread_local_store[:root] end
240
-
240
+
241
241
  # Attempts to find an object by name starting at +namespace+, performing
242
242
  # a lookup similar to Ruby's method of resolving a constant in a namespace.
243
- #
243
+ #
244
244
  # @example Looks for instance method #reverse starting from A::B::C
245
245
  # Registry.resolve(P("A::B::C"), "#reverse")
246
246
  # @example Looks for a constant in the root namespace
@@ -260,7 +260,7 @@ module YARD
260
260
  # @param [Boolean] proxy_fallback If +true+, returns a proxy representing
261
261
  # the unresolved path (namespace + name) if no object is found.
262
262
  # @return [CodeObjects::Base] the object if it is found
263
- # @return [CodeObjects::Proxy] a Proxy representing the object if
263
+ # @return [CodeObjects::Proxy] a Proxy representing the object if
264
264
  # +proxy_fallback+ is +true+.
265
265
  # @return [nil] if +proxy_fallback+ is +false+ and no object was found.
266
266
  # @see P
@@ -268,7 +268,7 @@ module YARD
268
268
  if namespace.is_a?(CodeObjects::Proxy)
269
269
  return proxy_fallback ? CodeObjects::Proxy.new(namespace, name) : nil
270
270
  end
271
-
271
+
272
272
  if namespace == :root || !namespace
273
273
  namespace = root
274
274
  else
@@ -298,24 +298,24 @@ module YARD
298
298
  end
299
299
 
300
300
  # @group Managing Source File Checksums
301
-
301
+
302
302
  # @return [Hash{String => String}] a set of checksums for files
303
303
  def checksums
304
304
  thread_local_store.checksums
305
305
  end
306
-
306
+
307
307
  # @param [String] data data to checksum
308
308
  # @return [String] the SHA1 checksum for data
309
309
  def checksum_for(data)
310
310
  Digest::SHA1.hexdigest(data)
311
311
  end
312
-
312
+
313
313
  # @group Managing Internal State (Advanced / Testing Only)
314
-
314
+
315
315
  # Whether or not the Registry storage should load everything into a
316
- # single object database (for disk efficiency), or spread them out
316
+ # single object database (for disk efficiency), or spread them out
317
317
  # (for load time efficiency).
318
- #
318
+ #
319
319
  # @note Setting this attribute to nil will offload the decision to
320
320
  # the {RegistryStore storage adapter}.
321
321
  # @return [Boolean, nil] if this value is set to nil, the storage
@@ -330,21 +330,21 @@ module YARD
330
330
  def proxy_types
331
331
  thread_local_store.proxy_types
332
332
  end
333
-
333
+
334
334
  # @group Legacy Methods
335
-
335
+
336
336
  # The registry singleton instance.
337
- #
337
+ #
338
338
  # @deprecated use Registry.methodname directly.
339
339
  # @return [Registry] returns the registry instance
340
340
  def instance; self end
341
-
341
+
342
342
  private
343
-
343
+
344
344
  # @group Accessing Objects in the Registry
345
345
 
346
346
  # Attempts to resolve a name in a namespace
347
- #
347
+ #
348
348
  # @param [CodeObjects::NamespaceObject] namespace the starting namespace
349
349
  # @param [String] name the name to look for
350
350
  def partial_resolve(namespace, name)
@@ -360,9 +360,9 @@ module YARD
360
360
  end
361
361
  nil
362
362
  end
363
-
363
+
364
364
  # @group Retrieving yardoc File Locations
365
-
365
+
366
366
  def global_yardoc_file(spec, for_writing = false)
367
367
  path = spec.full_gem_path
368
368
  yfile = File.join(path, DEFAULT_YARDOC_FILE)
@@ -372,7 +372,7 @@ module YARD
372
372
  return yfile
373
373
  end
374
374
  end
375
-
375
+
376
376
  def local_yardoc_file(spec, for_writing = false)
377
377
  path = Registry::LOCAL_YARDOC_INDEX
378
378
  FileUtils.mkdir_p(path) if for_writing
@@ -383,14 +383,14 @@ module YARD
383
383
  File.exist?(path) ? path : nil
384
384
  end
385
385
  end
386
-
386
+
387
387
  # @group Threading support
388
-
388
+
389
389
  # @since 0.6.5
390
390
  def thread_local_store
391
391
  Thread.current[:__yard_registry__] ||= clear
392
392
  end
393
-
393
+
394
394
  # @since 0.6.5
395
395
  def thread_local_store=(value)
396
396
  Thread.current[:__yard_registry__] = value
@@ -2,12 +2,12 @@ require 'fileutils'
2
2
 
3
3
  module YARD
4
4
  # The data store for the {Registry}.
5
- #
5
+ #
6
6
  # @see Registry
7
7
  # @see Serializers::YardocSerializer
8
8
  class RegistryStore
9
9
  attr_reader :proxy_types, :file, :checksums
10
-
10
+
11
11
  def initialize
12
12
  @file = nil
13
13
  @checksums = {}
@@ -19,9 +19,9 @@ module YARD
19
19
  @store[:root] = CodeObjects::RootObject.allocate
20
20
  @store[:root].send(:initialize, nil, :root)
21
21
  end
22
-
22
+
23
23
  # Gets a {CodeObjects::Base} from the store
24
- #
24
+ #
25
25
  # @param [String, Symbol] key the path name of the object to look for.
26
26
  # If it is empty or :root, returns the {#root} object.
27
27
  # @return [CodeObjects::Base, nil] a code object or nil if none is found
@@ -41,7 +41,7 @@ module YARD
41
41
  nil
42
42
  end
43
43
  end
44
-
44
+
45
45
  # Associates an object with a path
46
46
  # @param [String, Symbol] key the path name (:root or '' for root object)
47
47
  # @param [CodeObjects::Base] value the object to store
@@ -51,34 +51,34 @@ module YARD
51
51
  @store[:root] = value
52
52
  else
53
53
  @notfound.delete(key.to_sym)
54
- @store[key.to_sym] = value
54
+ @store[key.to_sym] = value
55
55
  end
56
56
  end
57
-
57
+
58
58
  alias [] get
59
59
  alias []= put
60
-
60
+
61
61
  def delete(key) @store.delete(key.to_sym) end
62
-
62
+
63
63
  # Gets all path names from the store. Loads the entire database
64
64
  # if +reload+ is +true+
65
- #
65
+ #
66
66
  # @param [Boolean] reload if false, does not load the entire database
67
67
  # before a lookup.
68
68
  # @return [Array<Symbol>] the path names of all the code objects
69
69
  def keys(reload = false) load_all if reload; @store.keys end
70
-
70
+
71
71
  # Gets all code objects from the store. Loads the entire database
72
72
  # if +reload+ is +true+
73
- #
73
+ #
74
74
  # @param [Boolean] reload if false, does not load the entire database
75
75
  # before a lookup.
76
76
  # @return [Array<CodeObjects::Base>] all the code objects
77
77
  def values(reload = false) load_all if reload; @store.values end
78
-
78
+
79
79
  # @return [CodeObjects::RootObject] the root object
80
80
  def root; @store[:root] end
81
-
81
+
82
82
  # @param [String, nil] file the name of the yardoc db to load
83
83
  # @return [Boolean] whether the database was loaded
84
84
  def load(file = nil)
@@ -92,7 +92,7 @@ module YARD
92
92
 
93
93
  # Loads the .yardoc file and loads all cached objects into memory
94
94
  # automatically.
95
- #
95
+ #
96
96
  # @param [String, nil] file the name of the yardoc db to load
97
97
  # @return [Boolean] whether the database was loaded
98
98
  # @see #load_all
@@ -105,7 +105,7 @@ module YARD
105
105
  false
106
106
  end
107
107
  end
108
-
108
+
109
109
  # Loads all cached objects into memory
110
110
  # @return [void]
111
111
  def load_all
@@ -113,7 +113,7 @@ module YARD
113
113
  return if @loaded_objects >= @available_objects
114
114
  log.debug "Loading entire database: #{@file} ..."
115
115
  objects = []
116
-
116
+
117
117
  all_disk_objects.sort_by {|x| x.size }.each do |path|
118
118
  if obj = @serializer.deserialize(path, true)
119
119
  objects << obj
@@ -125,7 +125,7 @@ module YARD
125
125
  @loaded_objects += objects.size
126
126
  log.debug "Loaded database (file='#{@file}' count=#{objects.size} total=#{@available_objects})"
127
127
  end
128
-
128
+
129
129
  # Saves the database to disk
130
130
  # @param [Boolean] merge if true, merges the data in memory with the
131
131
  # data on disk, otherwise the data on disk is deleted.
@@ -137,7 +137,7 @@ module YARD
137
137
  @serializer = Serializers::YardocSerializer.new(@file)
138
138
  end
139
139
  destroy unless merge
140
-
140
+
141
141
  sdb = Registry.single_object_db
142
142
  if sdb == true || (sdb == nil && keys.size < 3000)
143
143
  @serializer.serialize(@store)
@@ -150,9 +150,9 @@ module YARD
150
150
  write_checksums
151
151
  true
152
152
  end
153
-
153
+
154
154
  # Deletes the .yardoc database on disk
155
- #
155
+ #
156
156
  # @param [Boolean] force if force is not set to true, the file/directory
157
157
  # will only be removed if it ends with .yardoc. This helps with
158
158
  # cases where the directory might have been named incorrectly.
@@ -160,9 +160,9 @@ module YARD
160
160
  # otherwise.
161
161
  def destroy(force = false)
162
162
  if (!force && file =~ /\.yardoc$/) || force
163
- if File.file?(@file)
163
+ if File.file?(@file)
164
164
  # Handle silent upgrade of old .yardoc format
165
- File.unlink(@file)
165
+ File.unlink(@file)
166
166
  elsif File.directory?(@file)
167
167
  FileUtils.rm_rf(@file)
168
168
  end
@@ -171,21 +171,21 @@ module YARD
171
171
  false
172
172
  end
173
173
  end
174
-
174
+
175
175
  protected
176
-
176
+
177
177
  def objects_path
178
178
  @serializer.objects_path
179
179
  end
180
-
180
+
181
181
  def proxy_types_path
182
182
  @serializer.proxy_types_path
183
183
  end
184
-
184
+
185
185
  def checksums_path
186
186
  @serializer.checksums_path
187
187
  end
188
-
188
+
189
189
  def load_yardoc
190
190
  return false unless @file
191
191
  if File.directory?(@file) # new format
@@ -202,18 +202,18 @@ module YARD
202
202
  false
203
203
  end
204
204
  end
205
-
205
+
206
206
  private
207
207
 
208
208
  def load_yardoc_old
209
209
  @store, @proxy_types = *Marshal.load(File.read_binary(@file))
210
210
  end
211
-
211
+
212
212
  def load_proxy_types
213
213
  return unless File.file?(proxy_types_path)
214
214
  @proxy_types = Marshal.load(File.read_binary(proxy_types_path))
215
215
  end
216
-
216
+
217
217
  def load_checksums
218
218
  return unless File.file?(checksums_path)
219
219
  lines = File.readlines(checksums_path).map do |line|
@@ -221,7 +221,7 @@ module YARD
221
221
  end
222
222
  @checksums = Hash[lines]
223
223
  end
224
-
224
+
225
225
  def load_root
226
226
  if root = @serializer.deserialize('root')
227
227
  @loaded_objects += 1
@@ -238,11 +238,11 @@ module YARD
238
238
  def all_disk_objects
239
239
  Dir.glob(File.join(objects_path, '**/*')).select {|f| File.file?(f) }
240
240
  end
241
-
241
+
242
242
  def write_proxy_types
243
243
  File.open!(proxy_types_path, 'wb') {|f| f.write(Marshal.dump(@proxy_types)) }
244
244
  end
245
-
245
+
246
246
  def write_checksums
247
247
  File.open!(checksums_path, 'w') do |f|
248
248
  @checksums.each {|k, v| f.puts("#{k} #{v}") }