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
@@ -0,0 +1,8 @@
1
+ begin
2
+ require 'rubygems'
3
+ if defined?(Gem::VERSION) && Gem::VERSION >= '1.8.0'
4
+ require File.dirname(__FILE__) + '/backports/gem'
5
+ require File.dirname(__FILE__) + '/backports/source_index'
6
+ end
7
+ rescue LoadError
8
+ end
@@ -0,0 +1,57 @@
1
+ RubyGems is copyrighted free software by Chad Fowler, Rich Kilmer, Jim
2
+ Weirich and others. You can redistribute it and/or modify it under
3
+ either the terms of the MIT license (see the file MIT.txt), or the
4
+ conditions below:
5
+
6
+ 1. You may make and give away verbatim copies of the source form of the
7
+ software without restriction, provided that you duplicate all of the
8
+ original copyright notices and associated disclaimers.
9
+
10
+ 2. You may modify your copy of the software in any way, provided that
11
+ you do at least ONE of the following:
12
+
13
+ a. place your modifications in the Public Domain or otherwise
14
+ make them Freely Available, such as by posting said
15
+ modifications to Usenet or an equivalent medium, or by allowing
16
+ the author to include your modifications in the software.
17
+
18
+ b. use the modified software only within your corporation or
19
+ organization.
20
+
21
+ c. give non-standard executables non-standard names, with
22
+ instructions on where to get the original software distribution.
23
+
24
+ d. make other distribution arrangements with the author.
25
+
26
+ 3. You may distribute the software in object code or executable
27
+ form, provided that you do at least ONE of the following:
28
+
29
+ a. distribute the executables and library files of the software,
30
+ together with instructions (in the manual page or equivalent)
31
+ on where to get the original distribution.
32
+
33
+ b. accompany the distribution with the machine-readable source of
34
+ the software.
35
+
36
+ c. give non-standard executables non-standard names, with
37
+ instructions on where to get the original software distribution.
38
+
39
+ d. make other distribution arrangements with the author.
40
+
41
+ 4. You may modify and include the part of the software into any other
42
+ software (possibly commercial). But some files in the distribution
43
+ are not written by the author, so that they are not under these terms.
44
+
45
+ For the list of those files and their copying conditions, see the
46
+ file LEGAL.
47
+
48
+ 5. The scripts and library files supplied as input to or produced as
49
+ output from the software do not automatically fall under the
50
+ copyright of the software, but belong to whomever generated them,
51
+ and may be sold commercially, and may be aggregated with this
52
+ software.
53
+
54
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
55
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
56
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57
+ PURPOSE.
@@ -0,0 +1,20 @@
1
+ Copyright (c) Chad Fowler, Rich Kilmer, Jim Weirich and others.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,8 @@
1
+ module Gem
2
+ ##
3
+ # Returns the Gem::SourceIndex of specifications that are in the Gem.path
4
+
5
+ def self.source_index
6
+ @@source_index ||= SourceIndex.from_installed_gems
7
+ end
8
+ end
@@ -0,0 +1,353 @@
1
+ #--
2
+ # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+ require 'rubygems/specification'
8
+
9
+ ##
10
+ # The SourceIndex object indexes all the gems available from a
11
+ # particular source (e.g. a list of gem directories, or a remote
12
+ # source). A SourceIndex maps a gem full name to a gem
13
+ # specification.
14
+ #
15
+ # NOTE:: The class used to be named Cache, but that became
16
+ # confusing when cached source fetchers where introduced. The
17
+ # constant Gem::Cache is an alias for this class to allow old
18
+ # YAMLized source index objects to load properly.
19
+
20
+ class Gem::SourceIndex
21
+
22
+ include Enumerable
23
+
24
+ attr_reader :gems # :nodoc:
25
+
26
+ ##
27
+ # Directories to use to refresh this SourceIndex when calling refresh!
28
+
29
+ attr_accessor :spec_dirs
30
+
31
+ class << self
32
+ ##
33
+ # Factory method to construct a source index instance for a given
34
+ # path.
35
+ #
36
+ # deprecated::
37
+ # If supplied, from_installed_gems will act just like
38
+ # +from_gems_in+. This argument is deprecated and is provided
39
+ # just for backwards compatibility, and should not generally
40
+ # be used.
41
+ #
42
+ # return::
43
+ # SourceIndex instance
44
+
45
+ def from_installed_gems(*deprecated)
46
+ if deprecated.empty?
47
+ from_gems_in(*installed_spec_directories)
48
+ else
49
+ from_gems_in(*deprecated) # HACK warn
50
+ end
51
+ end
52
+
53
+ ##
54
+ # Returns a list of directories from Gem.path that contain specifications.
55
+
56
+ def installed_spec_directories
57
+ Gem.path.collect { |dir| File.join(dir, "specifications") }
58
+ end
59
+
60
+ ##
61
+ # Creates a new SourceIndex from the ruby format gem specifications in
62
+ # +spec_dirs+.
63
+
64
+ def from_gems_in(*spec_dirs)
65
+ source_index = new
66
+ source_index.spec_dirs = spec_dirs
67
+ source_index.refresh!
68
+ end
69
+
70
+ ##
71
+ # Loads a ruby-format specification from +file_name+ and returns the
72
+ # loaded spec.
73
+
74
+ def load_specification(file_name)
75
+ Gem::Specification.load file_name
76
+ end
77
+
78
+ end
79
+
80
+ ##
81
+ # Constructs a source index instance from the provided specifications, which
82
+ # is a Hash of gem full names and Gem::Specifications.
83
+ #--
84
+ # TODO merge @gems and @prerelease_gems and provide a separate method
85
+ # #prerelease_gems
86
+
87
+ def initialize(specifications={})
88
+ @gems = {}
89
+ specifications.each{ |full_name, spec| add_spec spec }
90
+ @spec_dirs = nil
91
+ end
92
+
93
+ # TODO: remove method
94
+ def all_gems
95
+ @gems
96
+ end
97
+
98
+ def prerelease_gems
99
+ @gems.reject{ |name, gem| !gem.version.prerelease? }
100
+ end
101
+
102
+ def released_gems
103
+ @gems.reject{ |name, gem| gem.version.prerelease? }
104
+ end
105
+
106
+ ##
107
+ # Reconstruct the source index from the specifications in +spec_dirs+.
108
+
109
+ def load_gems_in(*spec_dirs)
110
+ @gems.clear
111
+
112
+ spec_dirs.reverse_each do |spec_dir|
113
+ spec_files = Dir.glob File.join(spec_dir, '*.gemspec')
114
+
115
+ spec_files.each do |spec_file|
116
+ gemspec = Gem::Specification.load spec_file
117
+ add_spec gemspec if gemspec
118
+ end
119
+ end
120
+
121
+ self
122
+ end
123
+
124
+ ##
125
+ # Returns an Array specifications for the latest released versions
126
+ # of each gem in this index.
127
+
128
+ def latest_specs(include_prerelease=false)
129
+ result = Hash.new { |h,k| h[k] = [] }
130
+ latest = {}
131
+
132
+ sort.each do |_, spec|
133
+ name = spec.name
134
+ curr_ver = spec.version
135
+ prev_ver = latest.key?(name) ? latest[name].version : nil
136
+
137
+ next if !include_prerelease && curr_ver.prerelease?
138
+ next unless prev_ver.nil? or curr_ver >= prev_ver or
139
+ latest[name].platform != Gem::Platform::RUBY
140
+
141
+ if prev_ver.nil? or
142
+ (curr_ver > prev_ver and spec.platform == Gem::Platform::RUBY) then
143
+ result[name].clear
144
+ latest[name] = spec
145
+ end
146
+
147
+ if spec.platform != Gem::Platform::RUBY then
148
+ result[name].delete_if do |result_spec|
149
+ result_spec.platform == spec.platform
150
+ end
151
+ end
152
+
153
+ result[name] << spec
154
+ end
155
+
156
+ # TODO: why is this a hash while @gems is an array? Seems like
157
+ # structural similarity would be good.
158
+ result.values.flatten
159
+ end
160
+
161
+ ##
162
+ # An array including only the prerelease gemspecs
163
+
164
+ def prerelease_specs
165
+ prerelease_gems.values
166
+ end
167
+
168
+ ##
169
+ # An array including only the released gemspecs
170
+
171
+ def released_specs
172
+ released_gems.values
173
+ end
174
+
175
+ ##
176
+ # Add a gem specification to the source index.
177
+
178
+ def add_spec(gem_spec, name = gem_spec.full_name)
179
+ # No idea why, but the Indexer wants to insert them using original_name
180
+ # instead of full_name. So we make it an optional arg.
181
+ @gems[name] = gem_spec
182
+ end
183
+
184
+ ##
185
+ # Add gem specifications to the source index.
186
+
187
+ def add_specs(*gem_specs)
188
+ gem_specs.each do |spec|
189
+ add_spec spec
190
+ end
191
+ end
192
+
193
+ ##
194
+ # Remove a gem specification named +full_name+.
195
+
196
+ def remove_spec(full_name)
197
+ @gems.delete full_name
198
+ end
199
+
200
+ ##
201
+ # Iterate over the specifications in the source index.
202
+
203
+ def each(&block) # :yields: gem.full_name, gem
204
+ @gems.each(&block)
205
+ end
206
+
207
+ ##
208
+ # The gem specification given a full gem spec name.
209
+
210
+ def specification(full_name)
211
+ @gems[full_name]
212
+ end
213
+
214
+ ##
215
+ # The signature for the source index. Changes in the signature indicate a
216
+ # change in the index.
217
+
218
+ def index_signature
219
+ require 'digest'
220
+
221
+ Digest::SHA256.new.hexdigest(@gems.keys.sort.join(',')).to_s
222
+ end
223
+
224
+ ##
225
+ # The signature for the given gem specification.
226
+
227
+ def gem_signature(gem_full_name)
228
+ require 'digest'
229
+
230
+ Digest::SHA256.new.hexdigest(@gems[gem_full_name].to_yaml).to_s
231
+ end
232
+
233
+ def size
234
+ @gems.size
235
+ end
236
+ alias length size
237
+
238
+ ##
239
+ # Find a gem by an exact match on the short name.
240
+
241
+ def find_name(gem_name, requirement = Gem::Requirement.default)
242
+ dep = Gem::Dependency.new gem_name, requirement
243
+ search dep
244
+ end
245
+
246
+ ##
247
+ # Search for a gem by Gem::Dependency +gem_pattern+. If +only_platform+
248
+ # is true, only gems matching Gem::Platform.local will be returned. An
249
+ # Array of matching Gem::Specification objects is returned.
250
+ #
251
+ # For backwards compatibility, a String or Regexp pattern may be passed as
252
+ # +gem_pattern+, and a Gem::Requirement for +platform_only+. This
253
+ # behavior is deprecated and will be removed.
254
+
255
+ def search(gem_pattern, platform_only = false)
256
+ requirement = nil
257
+ only_platform = false
258
+
259
+ # TODO - Remove support and warning for legacy arguments after 2008/11
260
+ unless Gem::Dependency === gem_pattern
261
+ warn "#{Gem.location_of_caller.join ':'}:Warning: Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated, use #find_name"
262
+ end
263
+
264
+ case gem_pattern
265
+ when Regexp then
266
+ requirement = platform_only || Gem::Requirement.default
267
+ when Gem::Dependency then
268
+ only_platform = platform_only
269
+ requirement = gem_pattern.requirement
270
+
271
+ gem_pattern = if Regexp === gem_pattern.name then
272
+ gem_pattern.name
273
+ elsif gem_pattern.name.empty? then
274
+ //
275
+ else
276
+ /^#{Regexp.escape gem_pattern.name}$/
277
+ end
278
+ else
279
+ requirement = platform_only || Gem::Requirement.default
280
+ gem_pattern = /#{gem_pattern}/i
281
+ end
282
+
283
+ unless Gem::Requirement === requirement then
284
+ requirement = Gem::Requirement.create requirement
285
+ end
286
+
287
+ specs = all_gems.values.select do |spec|
288
+ spec.name =~ gem_pattern and
289
+ requirement.satisfied_by? spec.version
290
+ end
291
+
292
+ if only_platform then
293
+ specs = specs.select do |spec|
294
+ Gem::Platform.match spec.platform
295
+ end
296
+ end
297
+
298
+ specs.sort_by { |s| s.sort_obj }
299
+ end
300
+
301
+ ##
302
+ # Replaces the gems in the source index from specifications in the
303
+ # directories this source index was created from. Raises an exception if
304
+ # this source index wasn't created from a directory (via from_gems_in or
305
+ # from_installed_gems, or having spec_dirs set).
306
+
307
+ def refresh!
308
+ raise 'source index not created from disk' if @spec_dirs.nil?
309
+ load_gems_in(*@spec_dirs)
310
+ end
311
+
312
+ ##
313
+ # Returns an Array of Gem::Specifications that are not up to date.
314
+
315
+ def outdated
316
+ outdateds = []
317
+
318
+ latest_specs.each do |local|
319
+ dependency = Gem::Dependency.new local.name, ">= #{local.version}"
320
+
321
+ fetcher = Gem::SpecFetcher.fetcher
322
+ remotes = fetcher.find_matching dependency
323
+ remotes = remotes.map { |(_, version, _), _| version }
324
+
325
+ latest = remotes.sort.last
326
+
327
+ outdateds << local.name if latest and local.version < latest
328
+ end
329
+
330
+ outdateds
331
+ end
332
+
333
+ def ==(other) # :nodoc:
334
+ self.class === other and @gems == other.gems
335
+ end
336
+
337
+ def dump
338
+ Marshal.dump(self)
339
+ end
340
+
341
+ end
342
+
343
+ # :stopdoc:
344
+ module Gem
345
+
346
+ ##
347
+ # Cache is an alias for SourceIndex to allow older YAMLized source index
348
+ # objects to load properly.
349
+
350
+ Cache = SourceIndex unless defined?(Cache)
351
+
352
+ end
353
+ # :startdoc: