yard 0.9.28 → 0.9.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. checksums.yaml +4 -4
  2. data/LEGAL +29 -1
  3. data/lib/yard/autoload.rb +2 -1
  4. data/lib/yard/cli/command.rb +1 -1
  5. data/lib/yard/cli/yardoc.rb +1 -1
  6. data/lib/yard/code_objects/base.rb +4 -1
  7. data/lib/yard/docstring_parser.rb +1 -1
  8. data/lib/yard/handlers/ruby/attribute_handler.rb +1 -1
  9. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +1 -1
  10. data/lib/yard/handlers/ruby/mixin_handler.rb +13 -6
  11. data/lib/yard/i18n/locale.rb +1 -1
  12. data/lib/yard/i18n/message.rb +2 -2
  13. data/lib/yard/i18n/messages.rb +1 -1
  14. data/lib/yard/i18n/pot_generator.rb +1 -1
  15. data/lib/yard/options.rb +1 -1
  16. data/lib/yard/parser/ruby/ruby_parser.rb +8 -2
  17. data/lib/yard/registry_resolver.rb +2 -1
  18. data/lib/yard/server/commands/base.rb +1 -1
  19. data/lib/yard/server/http_utils.rb +512 -0
  20. data/lib/yard/server/rack_adapter.rb +24 -12
  21. data/lib/yard/tags/tag.rb +2 -2
  22. data/lib/yard/tags/types_explainer.rb +1 -1
  23. data/lib/yard/templates/helpers/html_helper.rb +1 -1
  24. data/lib/yard/version.rb +1 -1
  25. metadata +5 -208
  26. data/.dockerignore +0 -2
  27. data/.gitattributes +0 -4
  28. data/.github/FUNDING.yml +0 -3
  29. data/.github/ISSUE_TEMPLATE.md +0 -33
  30. data/.github/PULL_REQUEST_TEMPLATE.md +0 -12
  31. data/.github/workflows/ci.yml +0 -30
  32. data/.github/workflows/gem.yml +0 -19
  33. data/.gitignore +0 -14
  34. data/.rspec +0 -2
  35. data/.rubocop.yml +0 -112
  36. data/.yardopts +0 -26
  37. data/.yardopts_guide +0 -19
  38. data/.yardopts_i18n +0 -23
  39. data/CHANGELOG.md +0 -836
  40. data/CODE_OF_CONDUCT.md +0 -15
  41. data/CONTRIBUTING.md +0 -140
  42. data/Dockerfile.samus +0 -28
  43. data/Gemfile +0 -34
  44. data/Rakefile +0 -36
  45. data/SECURITY.md +0 -26
  46. data/benchmarks/builtins_vs_eval.rb +0 -24
  47. data/benchmarks/concat_vs_join.rb +0 -13
  48. data/benchmarks/erb_vs_erubis.rb +0 -54
  49. data/benchmarks/format_args.rb +0 -47
  50. data/benchmarks/generation.rb +0 -38
  51. data/benchmarks/marshal_vs_dbm.rb +0 -64
  52. data/benchmarks/parsing.rb +0 -46
  53. data/benchmarks/pathname_vs_string.rb +0 -51
  54. data/benchmarks/rdoc_vs_yardoc.rb +0 -11
  55. data/benchmarks/registry_store_types.rb +0 -49
  56. data/benchmarks/ri_vs_yri.rb +0 -19
  57. data/benchmarks/ripper_parser.rb +0 -13
  58. data/benchmarks/splat_vs_flatten.rb +0 -13
  59. data/benchmarks/template_erb.rb +0 -23
  60. data/benchmarks/template_format.rb +0 -7
  61. data/benchmarks/template_profile.rb +0 -18
  62. data/benchmarks/yri_cache.rb +0 -20
  63. data/docs/CodeObjects.md +0 -115
  64. data/docs/GettingStarted.md +0 -679
  65. data/docs/Handlers.md +0 -152
  66. data/docs/Overview.md +0 -61
  67. data/docs/Parser.md +0 -191
  68. data/docs/Tags.md +0 -283
  69. data/docs/TagsArch.md +0 -123
  70. data/docs/Templates.md +0 -496
  71. data/docs/WhatsNew.md +0 -1245
  72. data/docs/images/code-objects-class-diagram.png +0 -0
  73. data/docs/images/handlers-class-diagram.png +0 -0
  74. data/docs/images/overview-class-diagram.png +0 -0
  75. data/docs/images/parser-class-diagram.png +0 -0
  76. data/docs/images/tags-class-diagram.png +0 -0
  77. data/docs/templates/default/fulldoc/html/full_list_tag.erb +0 -9
  78. data/docs/templates/default/fulldoc/html/setup.rb +0 -6
  79. data/docs/templates/default/layout/html/setup.rb +0 -9
  80. data/docs/templates/default/layout/html/tag_list.erb +0 -11
  81. data/docs/templates/default/yard_tags/html/list.erb +0 -18
  82. data/docs/templates/default/yard_tags/html/setup.rb +0 -26
  83. data/docs/templates/plugin.rb +0 -70
  84. data/po/ja.po +0 -31108
  85. data/samus.json +0 -49
  86. data/tasks/prepare_tag.rake +0 -45
  87. data/tasks/update_error_map.rake +0 -53
  88. data/templates/default/class/dot/setup.rb +0 -7
  89. data/templates/default/class/dot/superklass.erb +0 -3
  90. data/templates/default/class/html/constructor_details.erb +0 -8
  91. data/templates/default/class/html/setup.rb +0 -2
  92. data/templates/default/class/html/subclasses.erb +0 -4
  93. data/templates/default/class/setup.rb +0 -36
  94. data/templates/default/class/text/setup.rb +0 -12
  95. data/templates/default/class/text/subclasses.erb +0 -5
  96. data/templates/default/constant/text/header.erb +0 -11
  97. data/templates/default/constant/text/setup.rb +0 -4
  98. data/templates/default/docstring/html/abstract.erb +0 -4
  99. data/templates/default/docstring/html/deprecated.erb +0 -1
  100. data/templates/default/docstring/html/index.erb +0 -5
  101. data/templates/default/docstring/html/note.erb +0 -6
  102. data/templates/default/docstring/html/private.erb +0 -4
  103. data/templates/default/docstring/html/returns_void.erb +0 -1
  104. data/templates/default/docstring/html/text.erb +0 -1
  105. data/templates/default/docstring/html/todo.erb +0 -6
  106. data/templates/default/docstring/setup.rb +0 -52
  107. data/templates/default/docstring/text/abstract.erb +0 -2
  108. data/templates/default/docstring/text/deprecated.erb +0 -2
  109. data/templates/default/docstring/text/index.erb +0 -2
  110. data/templates/default/docstring/text/note.erb +0 -4
  111. data/templates/default/docstring/text/private.erb +0 -2
  112. data/templates/default/docstring/text/returns_void.erb +0 -1
  113. data/templates/default/docstring/text/text.erb +0 -1
  114. data/templates/default/docstring/text/todo.erb +0 -4
  115. data/templates/default/fulldoc/html/css/common.css +0 -1
  116. data/templates/default/fulldoc/html/css/full_list.css +0 -58
  117. data/templates/default/fulldoc/html/css/style.css +0 -497
  118. data/templates/default/fulldoc/html/frames.erb +0 -17
  119. data/templates/default/fulldoc/html/full_list.erb +0 -37
  120. data/templates/default/fulldoc/html/full_list_class.erb +0 -2
  121. data/templates/default/fulldoc/html/full_list_file.erb +0 -7
  122. data/templates/default/fulldoc/html/full_list_method.erb +0 -10
  123. data/templates/default/fulldoc/html/js/app.js +0 -314
  124. data/templates/default/fulldoc/html/js/full_list.js +0 -216
  125. data/templates/default/fulldoc/html/js/jquery.js +0 -4
  126. data/templates/default/fulldoc/html/setup.rb +0 -241
  127. data/templates/default/layout/dot/header.erb +0 -6
  128. data/templates/default/layout/dot/setup.rb +0 -15
  129. data/templates/default/layout/html/breadcrumb.erb +0 -11
  130. data/templates/default/layout/html/files.erb +0 -11
  131. data/templates/default/layout/html/footer.erb +0 -5
  132. data/templates/default/layout/html/headers.erb +0 -15
  133. data/templates/default/layout/html/index.erb +0 -2
  134. data/templates/default/layout/html/layout.erb +0 -24
  135. data/templates/default/layout/html/listing.erb +0 -4
  136. data/templates/default/layout/html/objects.erb +0 -32
  137. data/templates/default/layout/html/script_setup.erb +0 -4
  138. data/templates/default/layout/html/search.erb +0 -13
  139. data/templates/default/layout/html/setup.rb +0 -89
  140. data/templates/default/method/html/header.erb +0 -17
  141. data/templates/default/method/setup.rb +0 -4
  142. data/templates/default/method/text/header.erb +0 -1
  143. data/templates/default/method_details/html/header.erb +0 -3
  144. data/templates/default/method_details/html/method_signature.erb +0 -25
  145. data/templates/default/method_details/html/source.erb +0 -10
  146. data/templates/default/method_details/setup.rb +0 -11
  147. data/templates/default/method_details/text/header.erb +0 -10
  148. data/templates/default/method_details/text/method_signature.erb +0 -12
  149. data/templates/default/method_details/text/setup.rb +0 -11
  150. data/templates/default/module/dot/child.erb +0 -1
  151. data/templates/default/module/dot/dependencies.erb +0 -3
  152. data/templates/default/module/dot/header.erb +0 -6
  153. data/templates/default/module/dot/info.erb +0 -14
  154. data/templates/default/module/dot/setup.rb +0 -15
  155. data/templates/default/module/html/attribute_details.erb +0 -10
  156. data/templates/default/module/html/attribute_summary.erb +0 -8
  157. data/templates/default/module/html/box_info.erb +0 -43
  158. data/templates/default/module/html/children.erb +0 -8
  159. data/templates/default/module/html/constant_summary.erb +0 -17
  160. data/templates/default/module/html/defines.erb +0 -3
  161. data/templates/default/module/html/header.erb +0 -5
  162. data/templates/default/module/html/inherited_attributes.erb +0 -14
  163. data/templates/default/module/html/inherited_constants.erb +0 -8
  164. data/templates/default/module/html/inherited_methods.erb +0 -19
  165. data/templates/default/module/html/item_summary.erb +0 -40
  166. data/templates/default/module/html/method_details_list.erb +0 -9
  167. data/templates/default/module/html/method_summary.erb +0 -14
  168. data/templates/default/module/html/methodmissing.erb +0 -12
  169. data/templates/default/module/html/pre_docstring.erb +0 -1
  170. data/templates/default/module/setup.rb +0 -167
  171. data/templates/default/module/text/children.erb +0 -10
  172. data/templates/default/module/text/class_meths_list.erb +0 -8
  173. data/templates/default/module/text/extends.erb +0 -8
  174. data/templates/default/module/text/header.erb +0 -7
  175. data/templates/default/module/text/includes.erb +0 -8
  176. data/templates/default/module/text/instance_meths_list.erb +0 -8
  177. data/templates/default/module/text/setup.rb +0 -13
  178. data/templates/default/onefile/html/files.erb +0 -5
  179. data/templates/default/onefile/html/headers.erb +0 -6
  180. data/templates/default/onefile/html/layout.erb +0 -17
  181. data/templates/default/onefile/html/readme.erb +0 -3
  182. data/templates/default/onefile/html/setup.rb +0 -62
  183. data/templates/default/root/dot/child.erb +0 -3
  184. data/templates/default/root/dot/setup.rb +0 -6
  185. data/templates/default/root/html/setup.rb +0 -2
  186. data/templates/default/tags/html/example.erb +0 -11
  187. data/templates/default/tags/html/index.erb +0 -3
  188. data/templates/default/tags/html/option.erb +0 -24
  189. data/templates/default/tags/html/overload.erb +0 -14
  190. data/templates/default/tags/html/see.erb +0 -8
  191. data/templates/default/tags/html/tag.erb +0 -20
  192. data/templates/default/tags/setup.rb +0 -57
  193. data/templates/default/tags/text/example.erb +0 -12
  194. data/templates/default/tags/text/index.erb +0 -1
  195. data/templates/default/tags/text/option.erb +0 -20
  196. data/templates/default/tags/text/overload.erb +0 -19
  197. data/templates/default/tags/text/see.erb +0 -11
  198. data/templates/default/tags/text/tag.erb +0 -13
  199. data/templates/guide/class/html/setup.rb +0 -2
  200. data/templates/guide/docstring/html/setup.rb +0 -2
  201. data/templates/guide/fulldoc/html/css/style.css +0 -108
  202. data/templates/guide/fulldoc/html/js/app.js +0 -33
  203. data/templates/guide/fulldoc/html/setup.rb +0 -74
  204. data/templates/guide/layout/html/layout.erb +0 -81
  205. data/templates/guide/layout/html/setup.rb +0 -25
  206. data/templates/guide/method/html/header.erb +0 -18
  207. data/templates/guide/method/html/setup.rb +0 -22
  208. data/templates/guide/module/html/header.erb +0 -7
  209. data/templates/guide/module/html/method_list.erb +0 -5
  210. data/templates/guide/module/html/setup.rb +0 -27
  211. data/templates/guide/onefile/html/files.erb +0 -4
  212. data/templates/guide/onefile/html/setup.rb +0 -6
  213. data/templates/guide/onefile/html/toc.erb +0 -3
  214. data/templates/guide/tags/html/setup.rb +0 -9
  215. data/yard.gemspec +0 -25
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'benchmark'
3
- require File.join(File.dirname(__FILE__), '..', 'lib', 'yard')
4
-
5
- def parse_and_select_objects
6
- YARD::Registry.load_yardoc(File.join(File.dirname(__FILE__), '..', '.yardoc'))
7
- YARD::Registry.load_all
8
- $paths = []
9
- 4.times { $paths << YARD::Registry.paths[rand(YARD::Registry.paths.size)] }
10
-
11
- $regular_registry = {}
12
- $types_registry = {}
13
- YARD::Registry.all.each do |object|
14
- $regular_registry[object.path] = object
15
- ($types_registry[object.type] ||= {})[object.path] = object
16
- end
17
- end
18
-
19
- def run_lookup
20
- $paths.select {|path| $regular_registry[path] }
21
- end
22
-
23
- def run_lookup_with_types
24
- $paths.select {|path| $types_registry.values.find {|list| list[path] } }
25
- end
26
-
27
- TIMES = 100_000
28
-
29
- parse_and_select_objects
30
- p $paths
31
- Benchmark.bmbm do |x|
32
- x.report("normal") { TIMES.times { run_lookup } }
33
- x.report("types") { TIMES.times { run_lookup_with_types } }
34
- end
35
-
36
- __END__
37
- # Run on March 22 2012
38
- ["YARD::Parser::Ruby::Legacy::RubyToken::TkUnknownChar#initialize",
39
- "YARD::Parser::C::CParser#enumerator",
40
- "YARD::CodeObjects::ClassObject#inherited_meths",
41
- "YARD::Parser::C::Statement#source="]
42
- Rehearsal ----------------------------------------------
43
- normal 0.180000 0.000000 0.180000 ( 0.182640)
44
- types 1.150000 0.010000 1.160000 ( 1.160219)
45
- ------------------------------------- total: 1.340000sec
46
-
47
- user system total real
48
- normal 0.170000 0.000000 0.170000 ( 0.165621)
49
- types 1.140000 0.000000 1.140000 ( 1.142269)
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
- require "benchmark"
3
-
4
- TIMES = 10
5
- Benchmark.bmbm do |x|
6
- x.report("ri") { TIMES.times { `ri -T YARD::Tags::Library` } }
7
- x.report("yri") { TIMES.times { `./bin/yri -T YARD::Tags::Library` } }
8
- end
9
-
10
- __END__
11
-
12
- Rehearsal ---------------------------------------
13
- ri 0.000000 0.020000 6.880000 ( 6.929591)
14
- yri 0.000000 0.000000 1.060000 ( 1.074840)
15
- ------------------------------ total: 7.940000sec
16
-
17
- user system total real
18
- ri 0.000000 0.020000 6.850000 ( 6.871660)
19
- yri 0.000000 0.010000 1.060000 ( 1.067585)
@@ -1,13 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
- require 'benchmark'
4
- require File.dirname(__FILE__) + '/../lib/yard'
5
-
6
- $files = Dir[File.dirname(__FILE__) + '/../lib/**/*.rb'].map {|f| File.read(f) }
7
- $files_rip = Dir[File.dirname(__FILE__) + '/../lib/**/*.rb'].map {|f| [File.read(f), f] }
8
-
9
- TIMES = 2
10
- Benchmark.bmbm do |x|
11
- x.report("rip-parser") { TIMES.times { $files_rip.each {|f| YARD::Parser::Ruby::RubyParser.parse(*f) } } }
12
- x.report("yard-parser ") { TIMES.times { $files.each {|f| YARD::Parser::Ruby::Legacy::StatementList.new(f) } } }
13
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
- require "benchmark"
3
-
4
- # To prove that flattening a small list is not significantly slower than
5
- # calling *list (used to get around create_tag list issue)
6
- $a = "FOO BAR BAZ"
7
- def foo(*args) args.last.inspect end
8
-
9
- TESTS = 10_000
10
- Benchmark.bmbm do |x|
11
- x.report("splat") { TESTS.times { foo(*$a) } }
12
- x.report("flatten") { TESTS.times { foo(*[$a].flatten) } }
13
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
- require "benchmark"
3
- require File.join(File.dirname(__FILE__), '..', 'lib', 'yard')
4
-
5
- YARD::Registry.load_yardoc(File.join(File.dirname(__FILE__), '..', '.yardoc'))
6
- obj = YARD::Registry.at("YARD::CodeObjects::Base")
7
-
8
- TIMES = 3
9
- Benchmark.bm do |x|
10
- x.report("trim-line") { TIMES.times { obj.format(:format => :html) } }
11
- module YARD
12
- module Templates
13
- module Template
14
- def erb(section, &block)
15
- erb = ERB.new(cache(section))
16
- erb.filename = cache_filename(section).to_s
17
- erb.result(binding, &block)
18
- end
19
- end
20
- end
21
- end
22
- x.report("no-trim ") { TIMES.times { obj.format(:format => :html) } }
23
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
- require "benchmark"
3
- require File.join(File.dirname(__FILE__), '..', 'lib', 'yard')
4
-
5
- YARD::Registry.load_yardoc(File.join(File.dirname(__FILE__), '..', '.yardoc'))
6
- obj = YARD::Registry.at("YARD::CodeObjects::Base")
7
- log.puts Benchmark.measure { obj.format(:format => :html) }
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'rubygems'
3
- require 'ruby-prof'
4
- # require 'benchmark'
5
- require File.join(File.dirname(__FILE__), '..', 'lib', 'yard')
6
-
7
- YARD::Registry.load_yardoc(File.join(File.dirname(__FILE__), '..', '.yardoc'))
8
- obj = YARD::Registry.at("YARD::CodeObjects::Base")
9
-
10
- # PerfTools::CpuProfiler.start("template_profile") do
11
- # end
12
-
13
- result = RubyProf.profile do
14
- obj.format(:format => :html, :no_highlight => true)
15
- end
16
-
17
- printer = RubyProf::CallTreePrinter.new(result)
18
- printer.print(STDOUT)
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
- require File.dirname(__FILE__) + "/../lib/yard"
3
- require "benchmark"
4
- include YARD::CLI
5
-
6
- class YARD::CLI::YRI
7
- def print_object(object) end
8
- end
9
-
10
- def remove_cache
11
- File.unlink(YRI::CACHE_FILE)
12
- end
13
-
14
- TIMES = 10
15
- NAME = 'YARD'
16
- remove_cache; YRI.run(NAME)
17
- Benchmark.bmbm do |x|
18
- x.report("cache ") { TIMES.times { YRI.run(NAME) } }
19
- x.report("no-cache") { TIMES.times { remove_cache; YRI.run(NAME) } }
20
- end
data/docs/CodeObjects.md DELETED
@@ -1,115 +0,0 @@
1
- # @title CodeObjects Architecture
2
-
3
- # CodeObjects Architecture
4
-
5
- Code objects are Ruby objects that describe the code being documented. For instance,
6
- all classes, modules, methods, etc. are all extracted from the Ruby source as code
7
- objects. All of these code objects extend from the {YARD::CodeObjects::Base} class, which
8
- provides basic attributes like source location, source code, name and path.
9
-
10
- ## CodeObjects Organization
11
-
12
- Code objects are divided into two basic types. {YARD::CodeObjects::NamespaceObject NamespaceObjects}
13
- and non-namespace objects. A namespace object refers to any object in Ruby that can have
14
- other objects defined inside of it. In the context of Ruby, this specifically means
15
- modules and classes (both of which are subclasses of `NamespaceObject`). These objects
16
- act like tree structures, maintaining a list of all of their direct children. All non
17
- namespace objects are simply subclasses of the Base class. The {YARD::CodeObjects::RootObject RootObject}
18
- is a special kind of `NamespaceObject` which refers to the top level namespace in Ruby.
19
- Methods that accept a namespace object as a parameter should also accept the symbol
20
- `:root` as a shortcut for the root object.
21
-
22
- The following is an overview of the classes within the `CodeObjects` namespace:
23
-
24
- ![CodeObjects Class Diagram](images/code-objects-class-diagram.png)
25
-
26
- ## Unique Path Representation
27
-
28
- All CodeObjects are uniquely defined by their implementation of {YARD::CodeObjects::Base#path}.
29
- This path is used to locate or store a code object in the {YARD::Registry}. It is therefore
30
- essential that any Base subclass return a unique String value for #path so that the
31
- object may co-exist with other objects in the Registry.
32
-
33
- In practice, a path is simply the conventional Ruby representation of a class,
34
- module, constant, class variable or method. For example, the following objects
35
- would have the following respective paths:
36
-
37
- * Class `Klass` inside module `Mod`: `Mod::Klass`
38
- * Instance method `bar` inside class `Foo`: `Foo#bar`
39
- * Class method `bar` inside class `Foo`: `Foo.bar`
40
- * Constant `VERSION` inside class `YARD`: `YARD::VERSION`
41
- * Class variable `@@abc` inside class `A`: `A::@@abc`
42
-
43
- ## Registry
44
-
45
- CodeObjects classes are coupled with the {YARD::Registry} class which keeps track of
46
- all instantiated code objects. This is an explicit design choice to allow objects
47
- to be fetched, cached, imported and exported from a centralized location. As mentioned
48
- above, this coupling is a result of the fact that each object is uniquely identified by
49
- its path, which is used to implement lookups. You can read more about the registry
50
- in the {YARD::Registry} class.
51
-
52
- ## Identity Map
53
-
54
- Code objects are instantiated using an identity-map like implementation that guarantees
55
- only one unique Ruby object exists for an object described by a specific path. This
56
- allows developers to create a code object without checking if it already exists in
57
- the {YARD::Registry}. The following example will only create one object:
58
-
59
- id = ClassObject.new(:root, "MyClass").object_id #=> 13352
60
- ClassObject.new(:root, "MyClass").object_id #=> 13352
61
-
62
- ## Proxy Objects
63
-
64
- In addition to providing access to existing objects, a {YARD::CodeObjects::Proxy}
65
- class exists which can represent an object at a path that may or may not have been
66
- created. This is necessary to represent a reference to an object in code that is
67
- never defined in the same body of source code, or perhaps defined later. If any
68
- attributes of a proxy are accessed, it will immediately be resolved to the object
69
- at its declared path. In the case where such an object exists, it will act as
70
- a delegate to the object. However, if the object does not exist, a warning will
71
- be raised. Whenever arbitrary code objects are used, care should be taken in
72
- order to make sure attributes are not accessed on unresolvable proxies. An
73
- unresolvable proxy will return a class name of `Proxy` and #type of `:proxy`,
74
- for example:
75
-
76
- P(:InvalidObject).type == :proxy #=> true
77
- P(:InvalidObject).is_a?(Proxy) #=> true
78
-
79
- ## Adding Data to Code Objects
80
-
81
- Code objects act as hash-like structures that allow any arbitrary value to be set.
82
- This allows easy extending of existing objects without creating custom subclasses.
83
- For instance, to add a timestamp to a method object (when it was modified, maybe),
84
- it is possible to simply do:
85
-
86
- object = MethodObject.new(:root, "my_method")
87
- object[:modified_at] = Time.now
88
-
89
- This value can now be retrieved on this object both by the hash `[]` syntax as
90
- well as like any other method:
91
-
92
- object.modified_at #=> 2009-06-03 20:08:46 -0400
93
-
94
- ## Creating a Custom CodeObject
95
-
96
- It should first be mentioned that creating a custom code object should not be
97
- necessary in most cases, except when functionality that cannot be represented
98
- by classical Ruby objects is added. A good example *might* be a test class,
99
- which although is technically a Ruby class, has a significantly different purpose
100
- in documentation and needs a different set of metadata, as well as its own
101
- representation in documentation.
102
-
103
- The {YARD::CodeObjects::Base#path} implementation is the most important part of the
104
- code object architecture. The first thing any custom code object must guarantee is
105
- that its path value is unique among all other objects. The recommended way to do this
106
- with custom objects is to add a descriptive prefix to the path. For example, the
107
- following is an implementation of the path for a hypothetical `FooObject`:
108
-
109
- def path
110
- "__FooPrefix" + sep + super
111
- end
112
-
113
- Note that if our FooObject is a `NamespaceObject`, meaning if it can have child
114
- FooObjects defined inside of it, you may need to verify that the prefix is only
115
- applied once.