bundler-maglev- 1.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. data/.gitignore +22 -0
  2. data/.travis.yml +32 -0
  3. data/CHANGELOG.md +805 -0
  4. data/ISSUES.md +62 -0
  5. data/LICENSE +23 -0
  6. data/README.md +29 -0
  7. data/Rakefile +212 -0
  8. data/UPGRADING.md +103 -0
  9. data/bin/bundle +22 -0
  10. data/bundler.gemspec +30 -0
  11. data/lib/bundler.rb +286 -0
  12. data/lib/bundler/capistrano.rb +11 -0
  13. data/lib/bundler/cli.rb +520 -0
  14. data/lib/bundler/definition.rb +438 -0
  15. data/lib/bundler/dependency.rb +134 -0
  16. data/lib/bundler/deployment.rb +58 -0
  17. data/lib/bundler/dsl.rb +257 -0
  18. data/lib/bundler/environment.rb +47 -0
  19. data/lib/bundler/gem_helper.rb +151 -0
  20. data/lib/bundler/gem_installer.rb +9 -0
  21. data/lib/bundler/gem_tasks.rb +2 -0
  22. data/lib/bundler/graph.rb +130 -0
  23. data/lib/bundler/index.rb +138 -0
  24. data/lib/bundler/installer.rb +97 -0
  25. data/lib/bundler/lazy_specification.rb +74 -0
  26. data/lib/bundler/lockfile_parser.rb +108 -0
  27. data/lib/bundler/remote_specification.rb +59 -0
  28. data/lib/bundler/resolver.rb +464 -0
  29. data/lib/bundler/rubygems_ext.rb +237 -0
  30. data/lib/bundler/rubygems_integration.rb +349 -0
  31. data/lib/bundler/runtime.rb +152 -0
  32. data/lib/bundler/settings.rb +115 -0
  33. data/lib/bundler/setup.rb +23 -0
  34. data/lib/bundler/shared_helpers.rb +71 -0
  35. data/lib/bundler/source.rb +708 -0
  36. data/lib/bundler/spec_set.rb +135 -0
  37. data/lib/bundler/templates/Executable +16 -0
  38. data/lib/bundler/templates/Gemfile +4 -0
  39. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  40. data/lib/bundler/templates/newgem/Rakefile.tt +1 -0
  41. data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
  42. data/lib/bundler/templates/newgem/gitignore.tt +4 -0
  43. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +9 -0
  44. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  45. data/lib/bundler/templates/newgem/newgem.gemspec.tt +24 -0
  46. data/lib/bundler/ui.rb +73 -0
  47. data/lib/bundler/vendor/thor.rb +358 -0
  48. data/lib/bundler/vendor/thor/actions.rb +314 -0
  49. data/lib/bundler/vendor/thor/actions/create_file.rb +105 -0
  50. data/lib/bundler/vendor/thor/actions/create_link.rb +57 -0
  51. data/lib/bundler/vendor/thor/actions/directory.rb +93 -0
  52. data/lib/bundler/vendor/thor/actions/empty_directory.rb +134 -0
  53. data/lib/bundler/vendor/thor/actions/file_manipulation.rb +270 -0
  54. data/lib/bundler/vendor/thor/actions/inject_into_file.rb +109 -0
  55. data/lib/bundler/vendor/thor/base.rb +576 -0
  56. data/lib/bundler/vendor/thor/core_ext/file_binary_read.rb +9 -0
  57. data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  58. data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +100 -0
  59. data/lib/bundler/vendor/thor/error.rb +30 -0
  60. data/lib/bundler/vendor/thor/group.rb +273 -0
  61. data/lib/bundler/vendor/thor/invocation.rb +168 -0
  62. data/lib/bundler/vendor/thor/parser.rb +4 -0
  63. data/lib/bundler/vendor/thor/parser/argument.rb +67 -0
  64. data/lib/bundler/vendor/thor/parser/arguments.rb +161 -0
  65. data/lib/bundler/vendor/thor/parser/option.rb +120 -0
  66. data/lib/bundler/vendor/thor/parser/options.rb +175 -0
  67. data/lib/bundler/vendor/thor/rake_compat.rb +66 -0
  68. data/lib/bundler/vendor/thor/runner.rb +309 -0
  69. data/lib/bundler/vendor/thor/shell.rb +88 -0
  70. data/lib/bundler/vendor/thor/shell/basic.rb +302 -0
  71. data/lib/bundler/vendor/thor/shell/color.rb +108 -0
  72. data/lib/bundler/vendor/thor/shell/html.rb +121 -0
  73. data/lib/bundler/vendor/thor/task.rb +113 -0
  74. data/lib/bundler/vendor/thor/util.rb +229 -0
  75. data/lib/bundler/vendor/thor/version.rb +3 -0
  76. data/lib/bundler/vendored_thor.rb +7 -0
  77. data/lib/bundler/version.rb +6 -0
  78. data/lib/bundler/vlad.rb +11 -0
  79. data/man/bundle-config.ronn +90 -0
  80. data/man/bundle-exec.ronn +111 -0
  81. data/man/bundle-install.ronn +317 -0
  82. data/man/bundle-package.ronn +59 -0
  83. data/man/bundle-update.ronn +176 -0
  84. data/man/bundle.ronn +80 -0
  85. data/man/gemfile.5.ronn +284 -0
  86. data/man/index.txt +6 -0
  87. data/spec/bundler/gem_helper_spec.rb +143 -0
  88. data/spec/cache/gems_spec.rb +230 -0
  89. data/spec/cache/git_spec.rb +12 -0
  90. data/spec/cache/path_spec.rb +27 -0
  91. data/spec/cache/platform_spec.rb +57 -0
  92. data/spec/install/deploy_spec.rb +197 -0
  93. data/spec/install/deprecated_spec.rb +37 -0
  94. data/spec/install/gems/c_ext_spec.rb +48 -0
  95. data/spec/install/gems/env_spec.rb +107 -0
  96. data/spec/install/gems/flex_spec.rb +313 -0
  97. data/spec/install/gems/groups_spec.rb +259 -0
  98. data/spec/install/gems/packed_spec.rb +84 -0
  99. data/spec/install/gems/platform_spec.rb +192 -0
  100. data/spec/install/gems/resolving_spec.rb +72 -0
  101. data/spec/install/gems/simple_case_spec.rb +770 -0
  102. data/spec/install/gems/sudo_spec.rb +74 -0
  103. data/spec/install/gems/win32_spec.rb +26 -0
  104. data/spec/install/gemspec_spec.rb +125 -0
  105. data/spec/install/git_spec.rb +570 -0
  106. data/spec/install/invalid_spec.rb +35 -0
  107. data/spec/install/path_spec.rb +405 -0
  108. data/spec/install/upgrade_spec.rb +26 -0
  109. data/spec/lock/git_spec.rb +35 -0
  110. data/spec/lock/lockfile_spec.rb +739 -0
  111. data/spec/other/check_spec.rb +221 -0
  112. data/spec/other/config_spec.rb +40 -0
  113. data/spec/other/console_spec.rb +54 -0
  114. data/spec/other/exec_spec.rb +248 -0
  115. data/spec/other/ext_spec.rb +37 -0
  116. data/spec/other/help_spec.rb +39 -0
  117. data/spec/other/init_spec.rb +40 -0
  118. data/spec/other/newgem_spec.rb +46 -0
  119. data/spec/other/open_spec.rb +35 -0
  120. data/spec/other/show_spec.rb +82 -0
  121. data/spec/quality_spec.rb +62 -0
  122. data/spec/resolver/basic_spec.rb +20 -0
  123. data/spec/resolver/platform_spec.rb +82 -0
  124. data/spec/runtime/executable_spec.rb +110 -0
  125. data/spec/runtime/load_spec.rb +107 -0
  126. data/spec/runtime/platform_spec.rb +90 -0
  127. data/spec/runtime/require_spec.rb +231 -0
  128. data/spec/runtime/setup_spec.rb +730 -0
  129. data/spec/runtime/with_clean_env_spec.rb +15 -0
  130. data/spec/spec_helper.rb +92 -0
  131. data/spec/support/builders.rb +597 -0
  132. data/spec/support/helpers.rb +239 -0
  133. data/spec/support/indexes.rb +112 -0
  134. data/spec/support/matchers.rb +77 -0
  135. data/spec/support/path.rb +71 -0
  136. data/spec/support/platforms.rb +53 -0
  137. data/spec/support/ruby_ext.rb +20 -0
  138. data/spec/support/rubygems_ext.rb +37 -0
  139. data/spec/support/rubygems_hax/platform.rb +11 -0
  140. data/spec/support/sudo.rb +21 -0
  141. data/spec/update/gems_spec.rb +122 -0
  142. data/spec/update/git_spec.rb +196 -0
  143. data/spec/update/source_spec.rb +51 -0
  144. metadata +296 -0
@@ -0,0 +1,237 @@
1
+ require 'pathname'
2
+
3
+ if defined?(Gem::QuickLoader)
4
+ # Gem Prelude makes me a sad panda :'(
5
+ Gem::QuickLoader.load_full_rubygems_library
6
+ end
7
+
8
+ require 'rubygems'
9
+ require 'rubygems/specification'
10
+
11
+ module Gem
12
+ @loaded_stacks = Hash.new { |h,k| h[k] = [] }
13
+
14
+ class Specification
15
+ attr_accessor :source, :location, :relative_loaded_from
16
+
17
+ alias_method :rg_full_gem_path, :full_gem_path
18
+ alias_method :rg_loaded_from, :loaded_from
19
+
20
+ def full_gem_path
21
+ source.respond_to?(:path) ?
22
+ Pathname.new(loaded_from).dirname.expand_path(Bundler.root).to_s :
23
+ rg_full_gem_path
24
+ end
25
+
26
+ def loaded_from
27
+ relative_loaded_from ?
28
+ source.path.join(relative_loaded_from).to_s :
29
+ rg_loaded_from
30
+ end
31
+
32
+ def load_paths
33
+ require_paths.map do |require_path|
34
+ if require_path.include?(full_gem_path)
35
+ require_path
36
+ else
37
+ File.join(full_gem_path, require_path)
38
+ end
39
+ end
40
+ end
41
+
42
+ # RubyGems 1.8+ used only.
43
+ remove_method :gem_dir if method_defined? :gem_dir
44
+ def gem_dir
45
+ full_gem_path
46
+ end
47
+
48
+ def groups
49
+ @groups ||= []
50
+ end
51
+
52
+ def git_version
53
+ if @loaded_from && File.exist?(File.join(full_gem_path, ".git"))
54
+ sha = Dir.chdir(full_gem_path){ `git rev-parse HEAD`.strip }
55
+ " #{sha[0..6]}"
56
+ end
57
+ end
58
+
59
+ def to_gemfile(path = nil)
60
+ gemfile = "source :gemcutter\n"
61
+ gemfile << dependencies_to_gemfile(nondevelopment_dependencies)
62
+ unless development_dependencies.empty?
63
+ gemfile << "\n"
64
+ gemfile << dependencies_to_gemfile(development_dependencies, :development)
65
+ end
66
+ gemfile
67
+ end
68
+
69
+ def nondevelopment_dependencies
70
+ dependencies - development_dependencies
71
+ end
72
+
73
+ def add_bundler_dependencies(*groups)
74
+ Bundler.ui.warn "#add_bundler_dependencies is deprecated and will " \
75
+ "be removed in Bundler 1.0. Instead, please use the #gemspec method " \
76
+ "in your Gemfile, which will pull in any dependencies specified in " \
77
+ "your gemspec"
78
+
79
+ groups = [:default] if groups.empty?
80
+ Bundler.definition.dependencies.each do |dep|
81
+ if dep.groups.include?(:development)
82
+ self.add_development_dependency(dep.name, dep.requirement.to_s)
83
+ elsif (dep.groups & groups).any?
84
+ self.add_dependency(dep.name, dep.requirement.to_s)
85
+ end
86
+ end
87
+ end
88
+
89
+ private
90
+
91
+ def dependencies_to_gemfile(dependencies, group = nil)
92
+ gemfile = ''
93
+ if dependencies.any?
94
+ gemfile << "group :#{group} do\n" if group
95
+ dependencies.each do |dependency|
96
+ gemfile << ' ' if group
97
+ gemfile << %|gem "#{dependency.name}"|
98
+ req = dependency.requirements_list.first
99
+ gemfile << %|, "#{req}"| if req
100
+ gemfile << "\n"
101
+ end
102
+ gemfile << "end\n" if group
103
+ end
104
+ gemfile
105
+ end
106
+
107
+ end
108
+
109
+ class Dependency
110
+ attr_accessor :source, :groups
111
+
112
+ alias eql? ==
113
+
114
+ def encode_with(coder)
115
+ to_yaml_properties.each do |ivar|
116
+ coder[ivar.to_s.sub(/^@/, '')] = instance_variable_get(ivar)
117
+ end
118
+ end
119
+
120
+ def to_yaml_properties
121
+ instance_variables.reject { |p| ["@source", "@groups"].include?(p.to_s) }
122
+ end
123
+
124
+ def to_lock
125
+ out = " #{name}"
126
+ unless requirement == Gem::Requirement.default
127
+ reqs = requirement.requirements.map{|o,v| "#{o} #{v}" }.sort.reverse
128
+ out << " (#{reqs.join(', ')})"
129
+ end
130
+ out
131
+ end
132
+
133
+ # Backport of performance enhancement added to Rubygems 1.4
134
+ def matches_spec?(spec)
135
+ # name can be a Regexp, so use ===
136
+ return false unless name === spec.name
137
+ return true if requirement.none?
138
+
139
+ requirement.satisfied_by?(spec.version)
140
+ end unless allocate.respond_to?(:matches_spec?)
141
+ end
142
+
143
+ class Requirement
144
+ # Backport of performance enhancement added to Rubygems 1.4
145
+ def none?
146
+ @none ||= (to_s == ">= 0")
147
+ end unless allocate.respond_to?(:none?)
148
+ end
149
+
150
+ class Platform
151
+ JAVA = Gem::Platform.new('java')
152
+ MSWIN = Gem::Platform.new('mswin32')
153
+ MINGW = Gem::Platform.new('x86-mingw32')
154
+
155
+ undef_method :hash if method_defined? :hash
156
+ def hash
157
+ @cpu.hash ^ @os.hash ^ @version.hash
158
+ end
159
+
160
+ alias eql? ==
161
+ end
162
+
163
+ end
164
+
165
+ module Bundler
166
+ class DepProxy
167
+
168
+ attr_reader :required_by, :__platform, :dep
169
+
170
+ def initialize(dep, platform)
171
+ @dep, @__platform, @required_by = dep, platform, []
172
+ end
173
+
174
+ def hash
175
+ @hash ||= dep.hash
176
+ end
177
+
178
+ def ==(o)
179
+ dep == o.dep && __platform == o.__platform
180
+ end
181
+
182
+ alias eql? ==
183
+
184
+ def type
185
+ @dep.type
186
+ end
187
+
188
+ def to_s
189
+ "#{name} (#{requirement}) #{__platform}"
190
+ end
191
+
192
+ private
193
+
194
+ def method_missing(*args)
195
+ @dep.send(*args)
196
+ end
197
+
198
+ end
199
+
200
+ module GemHelpers
201
+
202
+ GENERIC_CACHE = {}
203
+ GENERICS = [
204
+ Gem::Platform::JAVA,
205
+ Gem::Platform::MSWIN,
206
+ Gem::Platform::MINGW,
207
+ Gem::Platform::RUBY
208
+ ]
209
+
210
+ def generic(p)
211
+ return p if p == Gem::Platform::RUBY
212
+
213
+ GENERIC_CACHE[p] ||= begin
214
+ found = GENERICS.find do |p2|
215
+ p2.is_a?(Gem::Platform) && p.os == p2.os
216
+ end
217
+ found || Gem::Platform::RUBY
218
+ end
219
+ end
220
+ end
221
+
222
+ module MatchPlatform
223
+ include GemHelpers
224
+
225
+ def match_platform(p)
226
+ Gem::Platform::RUBY == platform or
227
+ platform.nil? or p == platform or
228
+ generic(Gem::Platform.new(platform)) == p
229
+ end
230
+ end
231
+ end
232
+
233
+ module Gem
234
+ class Specification
235
+ include Bundler::MatchPlatform
236
+ end
237
+ end
@@ -0,0 +1,349 @@
1
+ module Bundler
2
+ class RubygemsIntegration
3
+ def initialize
4
+ # Work around a RubyGems bug
5
+ configuration
6
+ end
7
+
8
+ def loaded_specs(name)
9
+ Gem.loaded_specs[name]
10
+ end
11
+
12
+ def mark_loaded(spec)
13
+ Gem.loaded_specs[spec.name] = spec
14
+ end
15
+
16
+ def path(obj)
17
+ obj.to_s
18
+ end
19
+
20
+ def platforms
21
+ Gem.platforms
22
+ end
23
+
24
+ def configuration
25
+ Gem.configuration
26
+ end
27
+
28
+ def ruby_engine
29
+ Gem.ruby_engine
30
+ end
31
+
32
+ def read_binary(path)
33
+ Gem.read_binary(path)
34
+ end
35
+
36
+ def inflate(obj)
37
+ Gem.inflate(obj)
38
+ end
39
+
40
+ def sources=(val)
41
+ Gem.sources = val
42
+ end
43
+
44
+ def sources
45
+ Gem.sources
46
+ end
47
+
48
+ def gem_dir
49
+ Gem.dir
50
+ end
51
+
52
+ def gem_bindir
53
+ Gem.bindir
54
+ end
55
+
56
+ def user_home
57
+ Gem.user_home
58
+ end
59
+
60
+ def gem_path
61
+ Gem.path
62
+ end
63
+
64
+ def marshal_spec_dir
65
+ Gem::MARSHAL_SPEC_DIR
66
+ end
67
+
68
+ def clear_paths
69
+ Gem.clear_paths
70
+ end
71
+
72
+ def bin_path(gem, bin, ver)
73
+ Gem.bin_path(gem, bin, ver)
74
+ end
75
+
76
+ def preserve_paths
77
+ # this is a no-op outside of Rubygems 1.8
78
+ yield
79
+ end
80
+
81
+ def ui=(obj)
82
+ Gem::DefaultUserInteraction.ui = obj
83
+ end
84
+
85
+ def fetch_specs(all, pre, &blk)
86
+ Gem::SpecFetcher.new.list(all, pre).each(&blk)
87
+ end
88
+
89
+ def with_build_args(args)
90
+ old_args = Gem::Command.build_args
91
+ begin
92
+ Gem::Command.build_args = args
93
+ yield
94
+ ensure
95
+ Gem::Command.build_args = old_args
96
+ end
97
+ end
98
+
99
+ def spec_from_gem(path)
100
+ Gem::Format.from_file_by_path(path).spec
101
+ end
102
+
103
+ def download_gem(spec, uri, path)
104
+ Gem::RemoteFetcher.fetcher.download(spec, uri, path)
105
+ end
106
+
107
+ def reverse_rubygems_kernel_mixin
108
+ # Disable rubygems' gem activation system
109
+ ::Kernel.class_eval do
110
+ if private_method_defined?(:gem_original_require)
111
+ alias rubygems_require require
112
+ alias require gem_original_require
113
+ end
114
+
115
+ undef gem
116
+ end
117
+ end
118
+
119
+ def replace_gem(specs)
120
+ executables = specs.map { |s| s.executables }.flatten
121
+
122
+ ::Kernel.send(:define_method, :gem) do |dep, *reqs|
123
+ if executables.include? File.basename(caller.first.split(':').first)
124
+ return
125
+ end
126
+ reqs.pop if reqs.last.is_a?(Hash)
127
+
128
+ unless dep.respond_to?(:name) && dep.respond_to?(:requirement)
129
+ dep = Gem::Dependency.new(dep, reqs)
130
+ end
131
+
132
+ spec = specs.find { |s| s.name == dep.name }
133
+
134
+ if spec.nil?
135
+
136
+ e = Gem::LoadError.new "#{dep.name} is not part of the bundle. Add it to Gemfile."
137
+ e.name = dep.name
138
+ if e.respond_to?(:requirement=)
139
+ e.requirement = dep.requirement
140
+ else
141
+ e.version_requirement = dep.requirement
142
+ end
143
+ raise e
144
+ elsif dep !~ spec
145
+ e = Gem::LoadError.new "can't activate #{dep}, already activated #{spec.full_name}. " \
146
+ "Make sure all dependencies are added to Gemfile."
147
+ e.name = dep.name
148
+ if e.respond_to?(:requirement=)
149
+ e.requirement = dep.requirement
150
+ else
151
+ e.version_requirement = dep.requirement
152
+ end
153
+ raise e
154
+ end
155
+
156
+ true
157
+ end
158
+ end
159
+
160
+ if defined? ::Deprecate
161
+ Deprecate = ::Deprecate
162
+ elsif defined? Gem::Deprecate
163
+ Deprecate = Gem::Deprecate
164
+ else
165
+ class Deprecate
166
+ def skip_during; yield; end
167
+ end
168
+ end
169
+
170
+ def stub_source_index137(specs)
171
+ # Rubygems versions lower than 1.7 use SourceIndex#from_gems_in
172
+ source_index_class = (class << Gem::SourceIndex ; self ; end)
173
+ source_index_class.send(:remove_method, :from_gems_in)
174
+ source_index_class.send(:define_method, :from_gems_in) do |*args|
175
+ source_index = Gem::SourceIndex.new
176
+ source_index.spec_dirs = *args
177
+ source_index.add_specs(*specs)
178
+ source_index
179
+ end
180
+ end
181
+
182
+ def stub_source_index170(specs)
183
+ Gem::SourceIndex.send(:alias_method, :old_initialize, :initialize)
184
+ Gem::SourceIndex.send(:define_method, :initialize) do |*args|
185
+ @gems = {}
186
+ # You're looking at this thinking: Oh! This is how I make those
187
+ # rubygems deprecations go away!
188
+ #
189
+ # You'd be correct BUT using of this method in production code
190
+ # must be approved by the rubygems team itself!
191
+ #
192
+ # This is your warning. If you use this and don't have approval
193
+ # we can't protect you.
194
+ #
195
+ Deprecate.skip_during do
196
+ self.spec_dirs = *args
197
+ add_specs(*specs)
198
+ end
199
+ end
200
+ end
201
+
202
+ # Used to make bin stubs that are not created by bundler work
203
+ # under bundler. The new Gem.bin_path only considers gems in
204
+ # +specs+
205
+ def replace_bin_path(specs)
206
+ gem_class = (class << Gem ; self ; end)
207
+ gem_class.send(:remove_method, :bin_path)
208
+ gem_class.send(:define_method, :bin_path) do |name, *args|
209
+ exec_name = args.first
210
+
211
+ if exec_name == 'bundle'
212
+ return ENV['BUNDLE_BIN_PATH']
213
+ end
214
+
215
+ spec = nil
216
+
217
+ if exec_name
218
+ spec = specs.find { |s| s.executables.include?(exec_name) }
219
+ spec or raise Gem::Exception, "can't find executable #{exec_name}"
220
+ else
221
+ spec = specs.find { |s| s.name == name }
222
+ exec_name = spec.default_executable or raise Gem::Exception, "no default executable for #{spec.full_name}"
223
+ end
224
+
225
+ gem_bin = File.join(spec.full_gem_path, spec.bindir, exec_name)
226
+ gem_from_path_bin = File.join(File.dirname(spec.loaded_from), spec.bindir, exec_name)
227
+ File.exist?(gem_bin) ? gem_bin : gem_from_path_bin
228
+ end
229
+ end
230
+
231
+ # Because Bundler has a static view of what specs are available,
232
+ # we don't #reflesh, so stub it out.
233
+ def replace_refresh
234
+ gem_class = (class << Gem ; self ; end)
235
+ gem_class.send(:remove_method, :refresh)
236
+ gem_class.send(:define_method, :refresh) { }
237
+ end
238
+
239
+ # Replace or hook into Rubygems to provide a bundlerized view
240
+ # of the world.
241
+ def replace_entrypoints(specs)
242
+ reverse_rubygems_kernel_mixin
243
+
244
+ replace_gem(specs)
245
+
246
+ stub_rubygems(specs)
247
+
248
+ replace_bin_path(specs)
249
+ replace_refresh
250
+
251
+ Gem.clear_paths
252
+ end
253
+
254
+ # This backports the correct segment generation code from Rubygems 1.4+
255
+ # by monkeypatching it into the method in Rubygems 1.3.6 and 1.3.7.
256
+ def backport_segment_generation
257
+ Gem::Version.send(:define_method, :segments) do
258
+ @segments_generated ||= false
259
+ unless @segments_generated
260
+ @segments ||= @version.scan(/[0-9a-z]+/i).map do |s|
261
+ /^\d+$/ =~ s ? s.to_i : s
262
+ end
263
+ end
264
+ @segments_generated = true
265
+ @segments
266
+ end
267
+ end
268
+
269
+ # Rubygems 1.4 through 1.6
270
+ class Legacy < RubygemsIntegration
271
+ def stub_rubygems(specs)
272
+ stub_source_index137(specs)
273
+ end
274
+
275
+ def all_specs
276
+ Gem.source_index.gems.values
277
+ end
278
+
279
+ def find_name(name)
280
+ Gem.source_index.find_name(name)
281
+ end
282
+ end
283
+
284
+ # Rubygems versions 1.3.6 and 1.3.7
285
+ class Ancient < Legacy
286
+ def initialize
287
+ super
288
+ backport_segment_generation
289
+ end
290
+ end
291
+
292
+ # Rubygems 1.7
293
+ class Transitional < Legacy
294
+ def stub_rubygems(specs)
295
+ stub_source_index170(specs)
296
+ end
297
+ end
298
+
299
+ # Rubygems 1.8.5
300
+ class Modern < RubygemsIntegration
301
+ def stub_rubygems(specs)
302
+ Gem::Specification.all = specs
303
+
304
+ Gem.post_reset {
305
+ Gem::Specification.all = specs
306
+ }
307
+
308
+ stub_source_index170(specs)
309
+ end
310
+
311
+ def all_specs
312
+ Gem::Specification.to_a
313
+ end
314
+
315
+ def find_name(name)
316
+ Gem::Specification.find_all_by_name name
317
+ end
318
+ end
319
+
320
+ # Rubygems 1.8.0 to 1.8.4
321
+ class AlmostModern < Modern
322
+ # Rubygems [>= 1.8.0, < 1.8.5] has a bug that changes Gem.dir whenever
323
+ # you call Gem::Installer#install with an :install_dir set. We have to
324
+ # change it back for our sudo mode to work.
325
+ def preserve_paths
326
+ old_dir, old_path = gem_dir, gem_path
327
+ yield
328
+ Gem.use_paths(old_dir, old_path)
329
+ end
330
+ end
331
+
332
+ end
333
+
334
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.8.5')
335
+ @rubygems = RubygemsIntegration::Modern.new
336
+ elsif Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.8.0')
337
+ @rubygems = RubygemsIntegration::AlmostModern.new
338
+ elsif Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.7.0')
339
+ @rubygems = RubygemsIntegration::Transitional.new
340
+ elsif Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.4.0')
341
+ @rubygems = RubygemsIntegration::Legacy.new
342
+ else # Rubygems 1.3.6 and 1.3.7
343
+ @rubygems = RubygemsIntegration::Ancient.new
344
+ end
345
+
346
+ class << self
347
+ attr_reader :rubygems
348
+ end
349
+ end