rubygems-update 0.9.4 → 0.9.5

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

Potentially problematic release.


This version of rubygems-update might be problematic. Click here for more details.

Files changed (225) hide show
  1. data/ChangeLog +587 -0
  2. data/README +0 -1
  3. data/Rakefile +39 -12
  4. data/TODO +0 -5
  5. data/bin/gem +7 -7
  6. data/bin/update_rubygems +1 -1
  7. data/examples/application/an-app.gemspec +1 -1
  8. data/gemspecs/cgikit-1.1.0.gemspec +1 -2
  9. data/gemspecs/jabber4r.gemspec +1 -1
  10. data/gemspecs/linguistics.gemspec +1 -1
  11. data/gemspecs/ook.gemspec +1 -1
  12. data/gemspecs/progressbar.gemspec +1 -1
  13. data/gemspecs/redcloth.gemspec +1 -1
  14. data/gemspecs/rublog.gemspec +1 -1
  15. data/gemspecs/ruby-doom.gemspec +1 -1
  16. data/gemspecs/rubyjdwp.gemspec +1 -1
  17. data/gemspecs/statistics.gemspec +1 -1
  18. data/lib/rubygems.rb +167 -105
  19. data/lib/rubygems/builder.rb +12 -10
  20. data/lib/rubygems/command.rb +177 -60
  21. data/lib/rubygems/command_manager.rb +30 -38
  22. data/lib/rubygems/commands/build_command.rb +42 -46
  23. data/lib/rubygems/commands/cert_command.rb +72 -69
  24. data/lib/rubygems/commands/check_command.rb +63 -63
  25. data/lib/rubygems/commands/cleanup_command.rb +25 -7
  26. data/lib/rubygems/commands/contents_command.rb +70 -62
  27. data/lib/rubygems/commands/dependency_command.rb +131 -86
  28. data/lib/rubygems/commands/environment_command.rb +67 -46
  29. data/lib/rubygems/commands/fetch_command.rb +62 -0
  30. data/lib/rubygems/commands/generate_index_command.rb +57 -0
  31. data/lib/rubygems/commands/help_command.rb +163 -73
  32. data/lib/rubygems/commands/install_command.rb +114 -128
  33. data/lib/rubygems/commands/list_command.rb +10 -8
  34. data/lib/rubygems/commands/lock_command.rb +101 -0
  35. data/lib/rubygems/commands/mirror_command.rb +105 -0
  36. data/lib/rubygems/commands/outdated_command.rb +24 -15
  37. data/lib/rubygems/commands/pristine_command.rb +118 -88
  38. data/lib/rubygems/commands/query_command.rb +109 -77
  39. data/lib/rubygems/commands/rdoc_command.rb +13 -10
  40. data/lib/rubygems/commands/search_command.rb +10 -8
  41. data/lib/rubygems/commands/server_command.rb +48 -0
  42. data/lib/rubygems/commands/sources_command.rb +104 -83
  43. data/lib/rubygems/commands/specification_command.rb +65 -51
  44. data/lib/rubygems/commands/uninstall_command.rb +17 -12
  45. data/lib/rubygems/commands/unpack_command.rb +68 -68
  46. data/lib/rubygems/commands/update_command.rb +72 -25
  47. data/lib/rubygems/commands/which_command.rb +86 -0
  48. data/lib/rubygems/config_file.rb +202 -78
  49. data/lib/rubygems/custom_require.rb +7 -88
  50. data/lib/rubygems/dependency.rb +65 -0
  51. data/lib/rubygems/dependency_installer.rb +232 -0
  52. data/lib/rubygems/dependency_list.rb +133 -105
  53. data/lib/rubygems/digest/md5.rb +4 -1
  54. data/lib/rubygems/digest/sha2.rb +1 -1
  55. data/lib/rubygems/doc_manager.rb +41 -19
  56. data/lib/rubygems/exceptions.rb +63 -0
  57. data/lib/rubygems/ext.rb +18 -0
  58. data/lib/rubygems/ext/builder.rb +56 -0
  59. data/lib/rubygems/ext/configure_builder.rb +24 -0
  60. data/lib/rubygems/ext/ext_conf_builder.rb +23 -0
  61. data/lib/rubygems/ext/rake_builder.rb +27 -0
  62. data/lib/rubygems/format.rb +16 -6
  63. data/lib/rubygems/gem_openssl.rb +43 -6
  64. data/lib/rubygems/gem_path_searcher.rb +84 -0
  65. data/lib/rubygems/gem_runner.rb +20 -5
  66. data/lib/rubygems/indexer.rb +163 -0
  67. data/lib/rubygems/indexer/abstract_index_builder.rb +80 -0
  68. data/lib/rubygems/indexer/marshal_index_builder.rb +17 -0
  69. data/lib/rubygems/indexer/master_index_builder.rb +53 -0
  70. data/lib/rubygems/indexer/quick_index_builder.rb +48 -0
  71. data/lib/rubygems/install_update_options.rb +87 -0
  72. data/lib/rubygems/installer.rb +316 -562
  73. data/lib/rubygems/local_remote_options.rb +106 -0
  74. data/lib/rubygems/old_format.rb +5 -13
  75. data/lib/rubygems/open-uri.rb +2 -0
  76. data/lib/rubygems/package.rb +28 -32
  77. data/lib/rubygems/platform.rb +187 -0
  78. data/lib/rubygems/remote_fetcher.rb +46 -29
  79. data/lib/rubygems/remote_installer.rb +11 -18
  80. data/lib/rubygems/requirement.rb +157 -0
  81. data/lib/rubygems/rubygems_version.rb +1 -1
  82. data/lib/rubygems/security.rb +715 -457
  83. data/lib/rubygems/server.rb +77 -59
  84. data/lib/rubygems/source_index.rb +154 -83
  85. data/lib/rubygems/source_info_cache.rb +73 -30
  86. data/lib/rubygems/source_info_cache_entry.rb +12 -3
  87. data/lib/rubygems/specification.rb +378 -145
  88. data/lib/rubygems/uninstaller.rb +183 -0
  89. data/lib/rubygems/user_interaction.rb +38 -9
  90. data/lib/rubygems/validator.rb +53 -24
  91. data/lib/rubygems/version.rb +126 -289
  92. data/lib/rubygems/version_option.rb +49 -0
  93. data/pkgs/sources/lib/sources.rb +1 -4
  94. data/pkgs/sources/sources.gemspec +3 -3
  95. data/scripts/gemdoc.rb +0 -1
  96. data/setup.rb +166 -1505
  97. data/test/bogussources.rb +0 -1
  98. data/test/data/gem-private_key.pem +27 -0
  99. data/test/data/gem-public_cert.pem +20 -0
  100. data/test/functional.rb +3 -105
  101. data/test/gemutilities.rb +145 -24
  102. data/test/insure_session.rb +0 -1
  103. data/test/{test_datadir.rb → test_config.rb} +7 -13
  104. data/test/test_gem.rb +360 -9
  105. data/test/test_gem_builder.rb +34 -0
  106. data/test/{test_command.rb → test_gem_command.rb} +119 -62
  107. data/test/{test_parse_commands.rb → test_gem_command_manager.rb} +64 -40
  108. data/test/test_gem_commands_build_command.rb +75 -0
  109. data/test/test_gem_commands_cert_command.rb +122 -0
  110. data/test/test_gem_commands_check_command.rb +25 -0
  111. data/test/test_gem_commands_contents_command.rb +92 -0
  112. data/test/test_gem_commands_dependency_command.rb +108 -0
  113. data/test/test_gem_commands_environment_command.rb +117 -0
  114. data/test/test_gem_commands_fetch_command.rb +34 -0
  115. data/test/test_gem_commands_generate_index_command.rb +32 -0
  116. data/test/test_gem_commands_install_command.rb +160 -0
  117. data/test/test_gem_commands_mirror_command.rb +56 -0
  118. data/test/test_gem_commands_pristine_command.rb +100 -0
  119. data/test/test_gem_commands_query_command.rb +82 -0
  120. data/test/test_gem_commands_sources_command.rb +147 -0
  121. data/test/test_gem_commands_specification_command.rb +93 -0
  122. data/test/test_gem_commands_unpack_command.rb +55 -0
  123. data/test/test_gem_config_file.rb +210 -0
  124. data/test/test_gem_dependency.rb +89 -0
  125. data/test/test_gem_dependency_installer.rb +542 -0
  126. data/test/test_gem_dependency_list.rb +212 -0
  127. data/test/test_gem_doc_manager.rb +32 -0
  128. data/test/test_gem_ext_configure_builder.rb +13 -17
  129. data/test/test_gem_ext_ext_conf_builder.rb +9 -9
  130. data/test/test_gem_ext_rake_builder.rb +23 -11
  131. data/test/test_gem_format.rb +69 -0
  132. data/test/test_gem_gem_path_searcher.rb +57 -0
  133. data/test/test_gem_gem_runner.rb +35 -0
  134. data/test/test_gem_indexer.rb +119 -0
  135. data/test/test_gem_install_update_options.rb +40 -0
  136. data/test/test_gem_installer.rb +796 -0
  137. data/test/test_gem_local_remote_options.rb +84 -0
  138. data/test/test_gem_outdated_command.rb +11 -9
  139. data/test/test_gem_platform.rb +240 -0
  140. data/test/{test_remote_fetcher.rb → test_gem_remote_fetcher.rb} +124 -55
  141. data/test/{test_remote_installer.rb → test_gem_remote_installer.rb} +3 -4
  142. data/test/test_gem_requirement.rb +223 -0
  143. data/test/test_gem_server.rb +71 -0
  144. data/test/test_gem_source_index.rb +429 -0
  145. data/test/test_gem_source_info_cache.rb +79 -17
  146. data/test/test_gem_source_info_cache_entry.rb +11 -9
  147. data/test/test_gem_specification.rb +738 -0
  148. data/test/test_gem_stream_ui.rb +117 -0
  149. data/test/test_gem_validator.rb +70 -0
  150. data/test/test_gem_version.rb +191 -0
  151. data/test/test_gem_version_option.rb +77 -0
  152. data/test/{test_require_gem.rb → test_kernel.rb} +19 -12
  153. data/test/test_open_uri.rb +1 -2
  154. data/test/test_package.rb +45 -34
  155. metadata +116 -141
  156. data/Releases +0 -127
  157. data/bin/gem_mirror +0 -73
  158. data/bin/gem_server +0 -6
  159. data/bin/gemlock +0 -127
  160. data/bin/gemri +0 -24
  161. data/bin/gemwhich +0 -89
  162. data/bin/index_gem_repository.rb +0 -302
  163. data/lib/gemconfigure.rb +0 -24
  164. data/lib/rubygems/gem_commands.rb +0 -273
  165. data/pkgs/sources/sources-0.0.1.gem +0 -0
  166. data/post-install.rb +0 -121
  167. data/test/brokenbuildgem.rb +0 -35
  168. data/test/data/PostMessage-0.0.1.gem +0 -0
  169. data/test/data/a-0.0.1.gem +0 -0
  170. data/test/data/a-0.0.2.gem +0 -0
  171. data/test/data/b-0.0.2.gem +0 -0
  172. data/test/data/broken-1.0.0.gem +0 -0
  173. data/test/data/broken_build/broken-build.gemspec +0 -20
  174. data/test/data/broken_build/ext/extconf.rb +0 -3
  175. data/test/data/broken_build/ext/foo.c +0 -1
  176. data/test/data/c-1.2.gem +0 -0
  177. data/test/data/gemhome/cache/a-0.0.1.gem +0 -0
  178. data/test/data/gemhome/cache/a-0.0.2.gem +0 -0
  179. data/test/data/gemhome/cache/b-0.0.2.gem +0 -0
  180. data/test/data/gemhome/cache/c-1.2.gem +0 -0
  181. data/test/data/gemhome/gems/a-0.0.1/lib/code.rb +0 -1
  182. data/test/data/gemhome/gems/a-0.0.2/lib/code.rb +0 -1
  183. data/test/data/gemhome/gems/b-0.0.2/lib/code.rb +0 -1
  184. data/test/data/gemhome/gems/c-1.2/lib/code.rb +0 -1
  185. data/test/data/gemhome/specifications/a-0.0.1.gemspec +0 -8
  186. data/test/data/gemhome/specifications/a-0.0.2.gemspec +0 -8
  187. data/test/data/gemhome/specifications/b-0.0.2.gemspec +0 -8
  188. data/test/data/gemhome/specifications/c-1.2.gemspec +0 -8
  189. data/test/data/legacy/keyedlist-0.4.0.ruby +0 -11
  190. data/test/data/legacy/keyedlist-0.4.0.yaml +0 -16
  191. data/test/data/lib/code.rb +0 -1
  192. data/test/data/one/README.one +0 -1
  193. data/test/data/one/lib/one.rb +0 -9
  194. data/test/data/one/one-0.0.1.gem +0 -0
  195. data/test/data/one/one.gemspec +0 -17
  196. data/test/data/one/one.yaml +0 -40
  197. data/test/data/post_install.gemspec +0 -19
  198. data/test/functional_extension_gems.rb +0 -48
  199. data/test/functional_generate_yaml_index.rb +0 -104
  200. data/test/gemenvironment.rb +0 -59
  201. data/test/io_capture.rb +0 -33
  202. data/test/mock/gems/gems/sources-0.0.1/lib/sources.rb +0 -11
  203. data/test/mock/gems/specifications/sources-0.0.1.gemspec +0 -8
  204. data/test/onegem.rb +0 -35
  205. data/test/test_builder.rb +0 -34
  206. data/test/test_check_command.rb +0 -34
  207. data/test/test_configfile.rb +0 -42
  208. data/test/test_dependency_list.rb +0 -169
  209. data/test/test_file_list.rb +0 -101
  210. data/test/test_format.rb +0 -49
  211. data/test/test_gem_sources_command.rb +0 -135
  212. data/test/test_gemloadpaths.rb +0 -51
  213. data/test/test_gempaths.rb +0 -170
  214. data/test/test_installer.rb +0 -369
  215. data/test/test_loadmanager.rb +0 -48
  216. data/test/test_process_commands.rb +0 -52
  217. data/test/test_source_index.rb +0 -231
  218. data/test/test_specific_extras.rb +0 -46
  219. data/test/test_specification.rb +0 -565
  220. data/test/test_user_interaction.rb +0 -48
  221. data/test/test_validator.rb +0 -59
  222. data/test/test_version_comparison.rb +0 -321
  223. data/test/testgem.rc +0 -7
  224. data/test/user_capture.rb +0 -7
  225. data/test/yaml_data.rb +0 -63
@@ -0,0 +1,86 @@
1
+ require 'rubygems/command'
2
+ require 'rubygems/gem_path_searcher'
3
+
4
+ class Gem::Commands::WhichCommand < Gem::Command
5
+
6
+ EXT = %w[.rb .rbw .so .dll] # HACK
7
+
8
+ def initialize
9
+ super 'which', 'Find the location of a library',
10
+ :search_gems_first => false, :show_all => false
11
+
12
+ add_option '-a', '--[no-]all', 'show all matching files' do |show_all, options|
13
+ options[:show_all] = show_all
14
+ end
15
+
16
+ add_option '-g', '--[no-]gems-first',
17
+ 'search gems before non-gems' do |gems_first, options|
18
+ options[:search_gems_first] = gems_first
19
+ end
20
+ end
21
+
22
+ def arguments # :nodoc:
23
+ "FILE name of file to find"
24
+ end
25
+
26
+ def defaults_str # :nodoc:
27
+ "--no-gems-first --no-all"
28
+ end
29
+
30
+ def usage # :nodoc:
31
+ "#{program_name} FILE [FILE ...]"
32
+ end
33
+
34
+ def execute
35
+ searcher = Gem::GemPathSearcher.new
36
+
37
+ options[:args].each do |arg|
38
+ dirs = $LOAD_PATH
39
+ spec = searcher.find arg
40
+
41
+ if spec then
42
+ if options[:search_gems_first] then
43
+ dirs = gem_paths(spec) + $LOAD_PATH
44
+ else
45
+ dirs = $LOAD_PATH + gem_paths(spec)
46
+ end
47
+
48
+ say "(checking gem #{spec.full_name} for #{arg})" if
49
+ Gem.configuration.verbose
50
+ end
51
+
52
+ paths = find_paths arg, dirs
53
+
54
+ if paths.empty? then
55
+ say "Can't find #{arg}"
56
+ else
57
+ say paths
58
+ end
59
+ end
60
+ end
61
+
62
+ def find_paths(package_name, dirs)
63
+ result = []
64
+
65
+ dirs.each do |dir|
66
+ EXT.each do |ext|
67
+ full_path = File.join dir, "#{package_name}#{ext}"
68
+ if File.exist? full_path then
69
+ result << full_path
70
+ return result unless options[:show_all]
71
+ end
72
+ end
73
+ end
74
+
75
+ result
76
+ end
77
+
78
+ def gem_paths(spec)
79
+ spec.require_paths.collect { |d| File.join spec.full_gem_path, d }
80
+ end
81
+
82
+ def usage # :nodoc:
83
+ "#{program_name} FILE [...]"
84
+ end
85
+
86
+ end
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env ruby
2
1
  #--
3
2
  # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
4
3
  # All rights reserved.
@@ -8,93 +7,218 @@
8
7
  require 'yaml'
9
8
  require 'rubygems'
10
9
 
11
- module Gem
10
+ # Store the gem command options specified in the configuration file. The
11
+ # config file object acts much like a hash.
12
12
 
13
- ####################################################################
14
- # Store the gem command options specified in the configuration file.
15
- # The config file object acts much like a hash.
13
+ class Gem::ConfigFile
14
+
15
+ DEFAULT_BACKTRACE = false
16
+ DEFAULT_BENCHMARK = false
17
+ DEFAULT_BULK_THRESHOLD = 1000
18
+ DEFAULT_VERBOSITY = true
19
+ DEFAULT_UPDATE_SOURCES = true
20
+
21
+ # List of arguments supplied to the config file object.
22
+ attr_reader :args
23
+
24
+ # True if we print backtraces on errors.
25
+ attr_writer :backtrace
26
+
27
+ # True if we are benchmarking this run.
28
+ attr_accessor :benchmark
29
+
30
+ # Bulk threshold value. If the number of missing gems are above
31
+ # this threshold value, then a bulk download technique is used.
32
+ attr_accessor :bulk_threshold
33
+
34
+ # Verbose level of output:
35
+ # * false -- No output
36
+ # * true -- Normal output
37
+ # * :loud -- Extra output
38
+ attr_accessor :verbose
39
+
40
+ # True if we want to update the SourceInfoCache every time, false otherwise
41
+ attr_accessor :update_sources
42
+
43
+ # Create the config file object. +args+ is the list of arguments
44
+ # from the command line.
45
+ #
46
+ # The following command line options are handled early here rather
47
+ # than later at the time most command options are processed.
48
+ #
49
+ # * --config-file and --config-file==NAME -- Obviously these need
50
+ # to be handled by the ConfigFile object to ensure we get the
51
+ # right config file.
52
+ #
53
+ # * --backtrace -- Backtrace needs to be turned on early so that
54
+ # errors before normal option parsing can be properly handled.
55
+ #
56
+ # * --debug -- Enable Ruby level debug messages. Handled early
57
+ # for the same reason as --backtrace.
16
58
  #
17
- class ConfigFile
18
- # True if the backtrace option has been specified.
19
- attr_reader :backtrace
20
-
21
- # List of arguments supplied to the config file object.
22
- attr_reader :args
23
-
24
- # Verbose level of output:
25
- # * false -- No output
26
- # * true -- Normal output
27
- # * :loud -- Extra output
28
- attr_accessor :verbose
29
-
30
- # Create the config file object. +args+ is the list of arguments
31
- # from the command line.
32
- #
33
- # The following command line options are handled early here rather
34
- # than later at the time most command options are processed.
35
- #
36
- # * --config-file and --config-file==NAME -- Obviously these need
37
- # to be handled by the ConfigFile object to ensure we get the
38
- # right config file.
39
- #
40
- # * --backtrace -- Backtrace needs to be turned on early so that
41
- # errors before normal option parsing can be properly handled.
42
- #
43
- # * --debug -- Enable Ruby level debug messages. Handled early
44
- # for the same reason as --backtrace.
45
- #
46
- def initialize(arg_list)
47
- @config_file_name = nil
48
- @verbose = true
49
- handle_arguments(arg_list)
50
- begin
51
- @hash = open(config_file_name) {|f| YAML.load(f) }
52
- rescue ArgumentError
53
- warn "Failed to load #{config_file_name}"
54
- rescue Errno::ENOENT
55
- # Ignore missing config file error.
56
- rescue Errno::EACCES
57
- warn "Failed to load #{config_file_name} due to permissions problem."
59
+ def initialize(arg_list)
60
+ @config_file_name = nil
61
+ need_config_file_name = false
62
+
63
+ arg_list = arg_list.map do |arg|
64
+ if need_config_file_name then
65
+ @config_file_name = arg
66
+ nil
67
+ elsif arg =~ /^--config-file=(.*)/ then
68
+ @config_file_name = $1
69
+ nil
70
+ elsif arg =~ /^--config-file$/ then
71
+ need_config_file_name = true
72
+ nil
73
+ else
74
+ arg
75
+ end
76
+ end.compact
77
+
78
+ @backtrace = DEFAULT_BACKTRACE
79
+ @benchmark = DEFAULT_BENCHMARK
80
+ @bulk_threshold = DEFAULT_BULK_THRESHOLD
81
+ @verbose = DEFAULT_VERBOSITY
82
+ @update_sources = DEFAULT_UPDATE_SOURCES
83
+
84
+ begin
85
+ # HACK $SAFE ok?
86
+ @hash = open(config_file_name.dup.untaint) {|f| YAML.load(f) }
87
+ rescue ArgumentError
88
+ warn "Failed to load #{config_file_name}"
89
+ rescue Errno::ENOENT
90
+ # Ignore missing config file error.
91
+ rescue Errno::EACCES
92
+ warn "Failed to load #{config_file_name} due to permissions problem."
93
+ end
94
+
95
+ @hash ||= {}
96
+
97
+ # HACK these override command-line args, which is bad
98
+ @backtrace = @hash[:backtrace] if @hash.key? :backtrace
99
+ @benchmark = @hash[:benchmark] if @hash.key? :benchmark
100
+ @bulk_threshold = @hash[:bulk_threshold] if @hash.key? :bulk_threshold
101
+ Gem.sources.replace @hash[:sources] if @hash.key? :sources
102
+ @verbose = @hash[:verbose] if @hash.key? :verbose
103
+ @update_sources = @hash[:update_sources] if @hash.key? :update_sources
104
+
105
+ handle_arguments arg_list
106
+ end
107
+
108
+ # True if the backtrace option has been specified, or debug is on.
109
+ def backtrace
110
+ @backtrace or $DEBUG
111
+ end
112
+
113
+ # The name of the configuration file.
114
+ def config_file_name
115
+ @config_file_name || Gem.config_file
116
+ end
117
+
118
+ # Delegates to @hash
119
+ def each(&block)
120
+ hash = @hash.dup
121
+ hash.delete :update_sources
122
+ hash.delete :verbose
123
+ hash.delete :benchmark
124
+ hash.delete :backtrace
125
+ hash.delete :bulk_threshold
126
+
127
+ yield :update_sources, @update_sources
128
+ yield :verbose, @verbose
129
+ yield :benchmark, @benchmark
130
+ yield :backtrace, @backtrace
131
+ yield :bulk_threshold, @bulk_threshold
132
+
133
+ yield 'config_file_name', @config_file_name if @config_file_name
134
+
135
+ hash.each(&block)
136
+ end
137
+
138
+ # Handle the command arguments.
139
+ def handle_arguments(arg_list)
140
+ @args = []
141
+
142
+ arg_list.each do |arg|
143
+ case arg
144
+ when /^--(backtrace|traceback)$/ then
145
+ @backtrace = true
146
+ when /^--bench(mark)?$/ then
147
+ @benchmark = true
148
+ when /^--debug$/ then
149
+ $DEBUG = true
150
+ else
151
+ @args << arg
58
152
  end
59
- @hash ||= {}
60
153
  end
154
+ end
61
155
 
62
- # The name of the configuration file.
63
- def config_file_name
64
- @config_file_name || Gem.config_file
156
+ # Really verbose mode gives you extra output.
157
+ def really_verbose
158
+ case verbose
159
+ when true, false, nil then false
160
+ else true
65
161
  end
162
+ end
163
+
164
+ # to_yaml only overwrites things you can't override on the command line.
165
+ def to_yaml # :nodoc:
166
+ yaml_hash = {}
167
+ yaml_hash[:backtrace] = @hash.key?(:backtrace) ? @hash[:backtrace] :
168
+ DEFAULT_BACKTRACE
169
+ yaml_hash[:benchmark] = @hash.key?(:benchmark) ? @hash[:benchmark] :
170
+ DEFAULT_BENCHMARK
171
+ yaml_hash[:bulk_threshold] = @hash.key?(:bulk_threshold) ?
172
+ @hash[:bulk_threshold] : DEFAULT_BULK_THRESHOLD
173
+ yaml_hash[:sources] = Gem.sources
174
+ yaml_hash[:update_sources] = @hash.key?(:update_sources) ?
175
+ @hash[:update_sources] : DEFAULT_UPDATE_SOURCES
176
+ yaml_hash[:verbose] = @hash.key?(:verbose) ? @hash[:verbose] :
177
+ DEFAULT_VERBOSITY
178
+
179
+ keys = yaml_hash.keys.map { |key| key.to_s }
180
+ keys << 'debug'
181
+ re = Regexp.union(*keys)
66
182
 
67
- # Return the configuration information for +key+.
68
- def [](key)
69
- @hash[key.to_s]
183
+ @hash.each do |key, value|
184
+ key = key.to_s
185
+ next if key =~ re
186
+ yaml_hash[key.to_s] = value
70
187
  end
71
188
 
72
- private
73
-
74
- # Handle the command arguments.
75
- def handle_arguments(arg_list)
76
- need_cfg_name = false
77
- @args = []
78
- arg_list.each do |arg|
79
- if need_cfg_name
80
- @config_file_name = arg
81
- need_cfg_name = false
82
- else
83
- case arg
84
- when /^--(traceback|backtrace)$/
85
- @backtrace = true
86
- when /^--debug$/
87
- $DEBUG = true
88
- when /^--config-file$/
89
- need_cfg_name = true
90
- when /^--config-file=(.+)$/
91
- @config_file_name = $1
92
- else
93
- @args << arg
94
- end
95
- end
96
- end
189
+ yaml_hash.to_yaml
190
+ end
191
+
192
+ # Writes out this config file, replacing its source.
193
+ def write
194
+ File.open config_file_name, 'w' do |fp|
195
+ fp.write self.to_yaml
97
196
  end
98
197
  end
99
198
 
199
+ # Return the configuration information for +key+.
200
+ def [](key)
201
+ @hash[key.to_s]
202
+ end
203
+
204
+ # Set configuration option +key+ to +value+.
205
+ def []=(key, value)
206
+ @hash[key.to_s] = value
207
+ end
208
+
209
+ def ==(other) # :nodoc:
210
+ self.class === other and
211
+ @backtrace == other.backtrace and
212
+ @benchmark == other.benchmark and
213
+ @bulk_threshold == other.bulk_threshold and
214
+ @verbose == other.verbose and
215
+ @update_sources == other.update_sources and
216
+ @hash == other.hash
217
+ end
218
+
219
+ protected
220
+
221
+ attr_reader :hash
222
+
100
223
  end
224
+
@@ -4,7 +4,7 @@
4
4
  # See LICENSE.txt for permissions.
5
5
  #++
6
6
 
7
- require 'rubygems/source_index'
7
+ require 'rubygems'
8
8
 
9
9
  module Kernel
10
10
  alias gem_original_require require # :nodoc:
@@ -26,94 +26,13 @@ module Kernel
26
26
  def require(path) # :nodoc:
27
27
  gem_original_require path
28
28
  rescue LoadError => load_error
29
- begin
30
- if spec = Gem.searcher.find(path)
31
- Gem.activate(spec.name, false, "= #{spec.version}")
32
- gem_original_require path
33
- else
34
- raise load_error
35
- end
29
+ if load_error.message =~ /\A[Nn]o such file to load -- #{Regexp.escape path}\z/ and
30
+ spec = Gem.searcher.find(path) then
31
+ Gem.activate(spec.name, false, "= #{spec.version}")
32
+ gem_original_require path
33
+ else
34
+ raise load_error
36
35
  end
37
36
  end
38
37
  end # module Kernel
39
38
 
40
- module Gem
41
-
42
- #
43
- # GemPathSearcher has the capability to find loadable files inside
44
- # gems. It generates data up front to speed up searches later.
45
- #
46
- class GemPathSearcher
47
-
48
- #
49
- # Initialise the data we need to make searches later.
50
- #
51
- def initialize
52
- # We want a record of all the installed gemspecs, in the order
53
- # we wish to examine them.
54
- @gemspecs = init_gemspecs
55
- # Map gem spec to glob of full require_path directories.
56
- # Preparing this information may speed up searches later.
57
- @lib_dirs = {}
58
- @gemspecs.each do |spec|
59
- @lib_dirs[spec.object_id] = lib_dirs(spec)
60
- end
61
- end
62
-
63
- #
64
- # Look in all the installed gems until a matching _path_ is found.
65
- # Return the _gemspec_ of the gem where it was found. If no match
66
- # is found, return nil.
67
- #
68
- # The gems are searched in alphabetical order, and in reverse
69
- # version order.
70
- #
71
- # For example:
72
- #
73
- # find('log4r') # -> (log4r-1.1 spec)
74
- # find('log4r.rb') # -> (log4r-1.1 spec)
75
- # find('rake/rdoctask') # -> (rake-0.4.12 spec)
76
- # find('foobarbaz') # -> nil
77
- #
78
- # Matching paths can have various suffixes ('.rb', '.so', and
79
- # others), which may or may not already be attached to _file_.
80
- # This method doesn't care about the full filename that matches;
81
- # only that there is a match.
82
- #
83
- def find(path)
84
- @gemspecs.each do |spec|
85
- return spec if matching_file(spec, path)
86
- end
87
- nil
88
- end
89
-
90
- private
91
-
92
- # Attempts to find a matching path using the require_paths of the
93
- # given _spec_.
94
- #
95
- # Some of the intermediate results are cached in @lib_dirs for
96
- # speed.
97
- def matching_file(spec, path) # :doc:
98
- glob = File.join @lib_dirs[spec.object_id], "#{path}#{Gem.suffix_pattern}"
99
- return true unless Dir[glob].select { |f| File.file?(f.untaint) }.empty?
100
- end
101
-
102
- # Return a list of all installed gemspecs, sorted by alphabetical
103
- # order and in reverse version order.
104
- def init_gemspecs
105
- Gem.source_index.map { |_, spec| spec }.sort { |a,b|
106
- (a.name <=> b.name).nonzero? || (b.version <=> a.version)
107
- }
108
- end
109
-
110
- # Returns library directories glob for a gemspec. For example,
111
- # '/usr/local/lib/ruby/gems/1.8/gems/foobar-1.0/{lib,ext}'
112
- def lib_dirs(spec)
113
- "#{spec.full_gem_path}/{#{spec.require_paths.join(',')}}"
114
- end
115
-
116
- end # class Gem::GemPathLoader
117
-
118
- end # module Gem
119
-