minigems 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +15 -0
- data/Rakefile +1 -1
- data/lib/minigems.rb +75 -54
- data/lib/minigems/core.rb +330 -0
- data/lib/minigems/script_helper.rb +4 -1
- data/spec/minigems_spec.rb +8 -4
- metadata +4 -4
data/README
CHANGED
@@ -34,6 +34,21 @@ rescue LoadError
|
|
34
34
|
require 'rubygems'
|
35
35
|
end
|
36
36
|
|
37
|
+
For best performance, use the Kernel#gem() method to load up the correct gem,
|
38
|
+
before doing any requires from it, preventing a more expensive glob operation.
|
39
|
+
|
40
|
+
The following:
|
41
|
+
|
42
|
+
require 'spec/task/spectask'
|
43
|
+
|
44
|
+
Can be easily improved as follows:
|
45
|
+
|
46
|
+
gem 'rspec'
|
47
|
+
require 'spec/task/spectask'
|
48
|
+
|
49
|
+
This is especially the case when there's no one-to-one mapping between the
|
50
|
+
file to require and de gem name (spec vs. rspec in the example above).
|
51
|
+
|
37
52
|
There's currently a patch pending on RubyForge, to get minigems into the
|
38
53
|
standard, rubygems system. If you like minigems, please post a vote/followup:
|
39
54
|
|
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ GEM_EMAIL = "info@atelierfabien.be"
|
|
15
15
|
|
16
16
|
GEM_NAME = "minigems"
|
17
17
|
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
18
|
-
GEM_VERSION = (Gem::MiniGems::VERSION || "0.9.
|
18
|
+
GEM_VERSION = (Gem::MiniGems::VERSION || "0.9.4") + PKG_BUILD
|
19
19
|
|
20
20
|
RELEASE_NAME = "REL #{GEM_VERSION}"
|
21
21
|
|
data/lib/minigems.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module Gem
|
2
2
|
unless const_defined?(:MiniGems)
|
3
3
|
module MiniGems
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
VERSION = "0.9.4"
|
6
|
+
|
6
7
|
# The next line needs to be kept exactly as shown; it's being replaced
|
7
8
|
# during minigems installation.
|
8
9
|
FULL_RUBYGEMS_METHODS = []
|
@@ -19,15 +20,14 @@ end
|
|
19
20
|
# Enable minigems unless rubygems has already loaded.
|
20
21
|
unless $LOADED_FEATURES.include?("rubygems.rb")
|
21
22
|
|
22
|
-
# Prevent full rubygems from loading
|
23
23
|
$LOADED_FEATURES << "rubygems.rb"
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
require 'minigems/core'
|
25
|
+
require 'rubygems/specification'
|
26
|
+
require 'pathname'
|
27
|
+
|
28
|
+
unless Gem::MiniGems.const_defined?(:INLINE_REGEXP)
|
29
|
+
Gem::MiniGems::INLINE_REGEXP = /^Inline_.*?\.#{Config::CONFIG['DLEXT']}/
|
30
|
+
end
|
31
31
|
|
32
32
|
module Kernel
|
33
33
|
|
@@ -35,29 +35,40 @@ unless $LOADED_FEATURES.include?("rubygems.rb")
|
|
35
35
|
Gem.activate(name, *versions)
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
if RUBY_VERSION < '1.9' then
|
39
|
+
|
40
|
+
alias :gem_original_require :require
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
42
|
+
# We replace Ruby's require with our own, which is capable of
|
43
|
+
# loading gems on demand.
|
44
|
+
#
|
45
|
+
# When you call <tt>require 'x'</tt>, this is what happens:
|
46
|
+
# * If the file can be loaded from the existing Ruby loadpath, it
|
47
|
+
# is.
|
48
|
+
# * Otherwise, installed gems are searched for a file that matches.
|
49
|
+
# If it's found in gem 'y', that gem is activated (added to the
|
50
|
+
# loadpath).
|
51
|
+
#
|
52
|
+
# The normal <tt>require</tt> functionality of returning false if
|
53
|
+
# that file has already been loaded is preserved.
|
54
|
+
#
|
55
|
+
def require(path) # :nodoc:
|
56
|
+
gem_original_require path
|
57
|
+
rescue LoadError => load_error
|
58
|
+
if File.basename(path).match(Gem::MiniGems::INLINE_REGEXP)
|
59
|
+
return true # RubyInline dynamicly created .so/.bundle
|
60
|
+
elsif load_error.message =~ /#{Regexp.escape path}\z/
|
61
|
+
if !path.include?('/') && (match = Gem.find_name(path))
|
62
|
+
Gem.activate_gem_from_path(match.first)
|
63
|
+
return gem_original_require(path)
|
64
|
+
elsif (spec = (Gem.find_in_source_path(path) || Gem.find_in_source_index(path)))
|
65
|
+
Gem.activate(spec.name, "= #{spec.version}")
|
66
|
+
return gem_original_require(path)
|
67
|
+
end
|
68
|
+
end
|
59
69
|
raise load_error
|
60
70
|
end
|
71
|
+
|
61
72
|
end
|
62
73
|
|
63
74
|
end
|
@@ -68,15 +79,6 @@ unless $LOADED_FEATURES.include?("rubygems.rb")
|
|
68
79
|
|
69
80
|
class Exception < RuntimeError; end
|
70
81
|
|
71
|
-
class LoadError < ::LoadError
|
72
|
-
attr_accessor :name, :version_requirement
|
73
|
-
end
|
74
|
-
|
75
|
-
# Whether minigems is being used or full rubygems has taken over.
|
76
|
-
def self.minigems?
|
77
|
-
not const_defined?(:SourceIndex)
|
78
|
-
end
|
79
|
-
|
80
82
|
# Keep track of loaded gems, maps gem name to full_name.
|
81
83
|
def self.loaded_gems
|
82
84
|
@loaded_gems ||= {}
|
@@ -92,7 +94,7 @@ unless $LOADED_FEATURES.include?("rubygems.rb")
|
|
92
94
|
def self.available?(name, *version_requirements)
|
93
95
|
version_requirements = Gem::Requirement.default if version_requirements.empty?
|
94
96
|
gem = Gem::Dependency.new(name, version_requirements)
|
95
|
-
not
|
97
|
+
not find_name(gem).nil?
|
96
98
|
end
|
97
99
|
|
98
100
|
# Activates an installed gem matching +gem+. The gem must satisfy
|
@@ -110,12 +112,10 @@ unless $LOADED_FEATURES.include?("rubygems.rb")
|
|
110
112
|
# More information on version requirements can be found in the
|
111
113
|
# Gem::Requirement and Gem::Version documentation.
|
112
114
|
def self.activate(gem, *version_requirements)
|
113
|
-
if match =
|
115
|
+
if match = find_name(gem, *version_requirements)
|
114
116
|
activate_gem_from_path(match.first)
|
115
|
-
elsif match =
|
117
|
+
elsif match = find_name(MiniGems.camel_case(gem), *version_requirements)
|
116
118
|
activate_gem_from_path(match.first)
|
117
|
-
elsif activate_from_source_path(gem)
|
118
|
-
true # The gem for the specified file was loaded correctly
|
119
119
|
else
|
120
120
|
unless gem.respond_to?(:name) && gem.respond_to?(:version_requirements)
|
121
121
|
gem = Gem::Dependency.new(gem, version_requirements)
|
@@ -235,9 +235,14 @@ unless $LOADED_FEATURES.include?("rubygems.rb")
|
|
235
235
|
end
|
236
236
|
|
237
237
|
# Find a file in the source path and activate its gem (best/highest match).
|
238
|
-
def self.
|
239
|
-
|
240
|
-
|
238
|
+
def self.find_in_source_path(path)
|
239
|
+
if ['.rb', '.rbw', '.so', '.bundle', '.dll', '.sl', '.jar'].include?(File.extname(path))
|
240
|
+
file_path = path
|
241
|
+
else
|
242
|
+
file_path = "#{path}.rb"
|
243
|
+
end
|
244
|
+
matched_paths = self.path.map do |gem_path|
|
245
|
+
[Pathname.new("#{gem_path}/gems"), Dir["#{gem_path}/gems/**/#{file_path}"]]
|
241
246
|
end
|
242
247
|
versions = matched_paths.inject([]) do |versions, (root_path, paths)|
|
243
248
|
paths.each do |matched_path|
|
@@ -249,23 +254,26 @@ unless $LOADED_FEATURES.include?("rubygems.rb")
|
|
249
254
|
gem_spec.loaded_from = gemspec_path
|
250
255
|
gem_dir = Pathname.new("#{root_path}/#{dir_name}")
|
251
256
|
|
252
|
-
filename = name + File.extname(matched_path)
|
253
257
|
relative_file = Pathname.new(matched_path).relative_path_from(gem_dir).to_s
|
254
|
-
if gem_spec.require_paths.any? { |req| File.join(req,
|
258
|
+
if gem_spec.require_paths.any? { |req| File.join(req, file_path) == relative_file }
|
255
259
|
versions << gem_spec
|
256
260
|
end
|
257
261
|
end
|
258
262
|
end
|
259
263
|
versions
|
260
264
|
end
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
+
versions.max { |a, b| a.version <=> b.version }
|
266
|
+
end
|
267
|
+
|
268
|
+
# Find a file in the Gem source index - loads up the full rubygems!
|
269
|
+
def self.find_in_source_index(path)
|
270
|
+
return nil if path == 'Win32API' && !Gem.win_platform?
|
271
|
+
puts "Switching from minigems to full rubygems..." if $MINIGEMS_DEBUG
|
272
|
+
Gem.searcher.find(path)
|
265
273
|
end
|
266
274
|
|
267
275
|
# Find the best (highest) matching gem version.
|
268
|
-
def self.
|
276
|
+
def self.find_name(gem, *version_requirements)
|
269
277
|
version_requirements = Gem::Requirement.default if version_requirements.empty?
|
270
278
|
unless gem.respond_to?(:name) && gem.respond_to?(:version_requirements)
|
271
279
|
gem = Gem::Dependency.new(gem, version_requirements)
|
@@ -297,6 +305,12 @@ unless $LOADED_FEATURES.include?("rubygems.rb")
|
|
297
305
|
# Load the full rubygems suite, at which point all minigems logic
|
298
306
|
# is being overridden, so all regular methods and classes are available.
|
299
307
|
def self.load_full_rubygems!
|
308
|
+
if $MINIGEMS_DEBUG
|
309
|
+
puts 'Loaded full RubyGems'
|
310
|
+
if !caller.first.to_s.match(/`const_missing'$/) && (require_entry = get_require_caller(caller))
|
311
|
+
puts "A gem was possibly implicitly loaded from #{require_entry}"
|
312
|
+
end
|
313
|
+
end
|
300
314
|
# Clear out any minigems methods
|
301
315
|
class << self
|
302
316
|
(MINIGEMS_METHODS - CORE_GEM_METHODS).each do |method_name|
|
@@ -307,6 +321,13 @@ unless $LOADED_FEATURES.include?("rubygems.rb")
|
|
307
321
|
::Kernel.module_eval { alias_method :require, :gem_original_require }
|
308
322
|
require $LOADED_FEATURES.delete("rubygems.rb")
|
309
323
|
end
|
324
|
+
|
325
|
+
def self.get_require_caller(callstack)
|
326
|
+
require_entry = callstack.find { |c| c =~ /`require'$/ }
|
327
|
+
if require_entry && (idx = callstack.index(require_entry)) && (entry = callstack[idx + 1])
|
328
|
+
entry
|
329
|
+
end
|
330
|
+
end
|
310
331
|
|
311
332
|
# Record all minigems methods - except the minigems? predicate method.
|
312
333
|
MINIGEMS_METHODS = Gem.methods(false) - ["minigems?"]
|
@@ -0,0 +1,330 @@
|
|
1
|
+
require 'rubygems/rubygems_version'
|
2
|
+
require 'rubygems/defaults'
|
3
|
+
|
4
|
+
module Gem
|
5
|
+
class LoadError < ::LoadError
|
6
|
+
attr_accessor :name, :version_requirement
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Gem
|
11
|
+
|
12
|
+
ConfigMap = {} unless defined?(ConfigMap)
|
13
|
+
require 'rbconfig'
|
14
|
+
RbConfig = Config unless defined? ::RbConfig
|
15
|
+
|
16
|
+
ConfigMap.merge!(
|
17
|
+
:BASERUBY => RbConfig::CONFIG["BASERUBY"],
|
18
|
+
:EXEEXT => RbConfig::CONFIG["EXEEXT"],
|
19
|
+
:RUBY_INSTALL_NAME => RbConfig::CONFIG["RUBY_INSTALL_NAME"],
|
20
|
+
:RUBY_SO_NAME => RbConfig::CONFIG["RUBY_SO_NAME"],
|
21
|
+
:arch => RbConfig::CONFIG["arch"],
|
22
|
+
:bindir => RbConfig::CONFIG["bindir"],
|
23
|
+
:datadir => RbConfig::CONFIG["datadir"],
|
24
|
+
:libdir => RbConfig::CONFIG["libdir"],
|
25
|
+
:ruby_install_name => RbConfig::CONFIG["ruby_install_name"],
|
26
|
+
:ruby_version => RbConfig::CONFIG["ruby_version"],
|
27
|
+
:sitedir => RbConfig::CONFIG["sitedir"],
|
28
|
+
:sitelibdir => RbConfig::CONFIG["sitelibdir"],
|
29
|
+
:vendordir => RbConfig::CONFIG["vendordir"] ,
|
30
|
+
:vendorlibdir => RbConfig::CONFIG["vendorlibdir"]
|
31
|
+
)
|
32
|
+
|
33
|
+
DIRECTORIES = %w[cache doc gems specifications] unless defined?(DIRECTORIES)
|
34
|
+
|
35
|
+
RubyGemsPackageVersion = RubyGemsVersion unless defined?(RubyGemsPackageVersion)
|
36
|
+
|
37
|
+
##
|
38
|
+
# An Array of Regexps that match windows ruby platforms.
|
39
|
+
|
40
|
+
unless defined?(WIN_PATTERNS)
|
41
|
+
WIN_PATTERNS = [/bccwin/i, /cygwin/i, /djgpp/i, /mingw/i, /mswin/i, /wince/i]
|
42
|
+
end
|
43
|
+
|
44
|
+
@@win_platform = nil
|
45
|
+
|
46
|
+
@platforms = []
|
47
|
+
@ruby = nil
|
48
|
+
|
49
|
+
##
|
50
|
+
# Whether minigems is being used or full rubygems has taken over.
|
51
|
+
|
52
|
+
def self.minigems?
|
53
|
+
not const_defined?(:SourceIndex)
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# The path to the running Ruby interpreter.
|
58
|
+
|
59
|
+
def self.ruby
|
60
|
+
if @ruby.nil? then
|
61
|
+
@ruby = File.join(ConfigMap[:bindir], ConfigMap[:ruby_install_name])
|
62
|
+
@ruby << ConfigMap[:EXEEXT]
|
63
|
+
# escape string in case path to ruby executable contain spaces.
|
64
|
+
@ruby.sub!(/.*\s.*/m, '"\&"')
|
65
|
+
end
|
66
|
+
@ruby
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# A Gem::Version for the currently running ruby.
|
71
|
+
|
72
|
+
def self.ruby_version
|
73
|
+
return @ruby_version if defined? @ruby_version
|
74
|
+
version = RUBY_VERSION.dup
|
75
|
+
version << ".#{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
|
76
|
+
@ruby_version = Gem::Version.new version
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Is this a windows platform?
|
81
|
+
|
82
|
+
def self.win_platform?
|
83
|
+
if @@win_platform.nil? then
|
84
|
+
@@win_platform = !!WIN_PATTERNS.find { |r| RUBY_PLATFORM =~ r }
|
85
|
+
end
|
86
|
+
@@win_platform
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# The path where gem executables are to be installed.
|
91
|
+
|
92
|
+
def self.bindir(install_dir=Gem.dir)
|
93
|
+
return File.join(install_dir, 'bin') unless
|
94
|
+
install_dir.to_s == Gem.default_dir
|
95
|
+
Gem.default_bindir
|
96
|
+
end
|
97
|
+
|
98
|
+
##
|
99
|
+
# The path where gems are to be installed.
|
100
|
+
|
101
|
+
def self.dir
|
102
|
+
@gem_home ||= nil
|
103
|
+
set_home(ENV['GEM_HOME'] || default_dir) unless @gem_home
|
104
|
+
@gem_home
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# Quietly ensure the named Gem directory contains all the proper
|
109
|
+
# subdirectories. If we can't create a directory due to a permission
|
110
|
+
# problem, then we will silently continue.
|
111
|
+
|
112
|
+
def self.ensure_gem_subdirectories(gemdir)
|
113
|
+
require 'fileutils'
|
114
|
+
|
115
|
+
Gem::DIRECTORIES.each do |filename|
|
116
|
+
fn = File.join gemdir, filename
|
117
|
+
FileUtils.mkdir_p fn rescue nil unless File.exist? fn
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
##
|
122
|
+
# Finds the user's home directory.
|
123
|
+
#--
|
124
|
+
# Some comments from the ruby-talk list regarding finding the home
|
125
|
+
# directory:
|
126
|
+
#
|
127
|
+
# I have HOME, USERPROFILE and HOMEDRIVE + HOMEPATH. Ruby seems
|
128
|
+
# to be depending on HOME in those code samples. I propose that
|
129
|
+
# it should fallback to USERPROFILE and HOMEDRIVE + HOMEPATH (at
|
130
|
+
# least on Win32).
|
131
|
+
|
132
|
+
def self.find_home
|
133
|
+
['HOME', 'USERPROFILE'].each do |homekey|
|
134
|
+
return ENV[homekey] if ENV[homekey]
|
135
|
+
end
|
136
|
+
|
137
|
+
if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] then
|
138
|
+
return "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}"
|
139
|
+
end
|
140
|
+
|
141
|
+
begin
|
142
|
+
File.expand_path("~")
|
143
|
+
rescue
|
144
|
+
File::ALT_SEPARATOR ? "C:/" : "/"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
private_class_method :find_home
|
149
|
+
|
150
|
+
##
|
151
|
+
# The index to insert activated gem paths into the $LOAD_PATH.
|
152
|
+
|
153
|
+
def self.load_path_insert_index
|
154
|
+
$LOAD_PATH.index ConfigMap[:sitelibdir]
|
155
|
+
end
|
156
|
+
|
157
|
+
##
|
158
|
+
# The file name and line number of the caller of the caller of this method.
|
159
|
+
|
160
|
+
def self.location_of_caller
|
161
|
+
file, lineno = caller[1].split(':')
|
162
|
+
lineno = lineno.to_i
|
163
|
+
[file, lineno]
|
164
|
+
end
|
165
|
+
|
166
|
+
private_class_method :location_of_caller
|
167
|
+
|
168
|
+
##
|
169
|
+
# The version of the Marshal format for your Ruby.
|
170
|
+
|
171
|
+
def self.marshal_version
|
172
|
+
"#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
|
173
|
+
end
|
174
|
+
|
175
|
+
##
|
176
|
+
# Array of paths to search for Gems.
|
177
|
+
|
178
|
+
def self.path
|
179
|
+
@gem_path ||= nil
|
180
|
+
|
181
|
+
unless @gem_path then
|
182
|
+
paths = if ENV['GEM_PATH'] then
|
183
|
+
[ENV['GEM_PATH']]
|
184
|
+
else
|
185
|
+
[default_path]
|
186
|
+
end
|
187
|
+
|
188
|
+
if defined?(APPLE_GEM_HOME) and not ENV['GEM_PATH'] then
|
189
|
+
paths << APPLE_GEM_HOME
|
190
|
+
end
|
191
|
+
|
192
|
+
set_paths paths.compact.join(File::PATH_SEPARATOR)
|
193
|
+
end
|
194
|
+
|
195
|
+
@gem_path
|
196
|
+
end
|
197
|
+
|
198
|
+
##
|
199
|
+
# Set array of platforms this RubyGems supports (primarily for testing).
|
200
|
+
|
201
|
+
def self.platforms=(platforms)
|
202
|
+
@platforms = platforms
|
203
|
+
end
|
204
|
+
|
205
|
+
##
|
206
|
+
# Array of platforms this RubyGems supports.
|
207
|
+
|
208
|
+
def self.platforms
|
209
|
+
@platforms ||= []
|
210
|
+
if @platforms.empty?
|
211
|
+
@platforms = [Gem::Platform::RUBY, Gem::Platform.local]
|
212
|
+
end
|
213
|
+
@platforms
|
214
|
+
end
|
215
|
+
|
216
|
+
##
|
217
|
+
# The directory prefix this RubyGems was installed at.
|
218
|
+
|
219
|
+
def self.prefix
|
220
|
+
prefix = File.dirname File.expand_path(File.join(__FILE__, '..'))
|
221
|
+
|
222
|
+
if File.dirname(prefix) == File.expand_path(ConfigMap[:sitelibdir]) or
|
223
|
+
File.dirname(prefix) == File.expand_path(ConfigMap[:libdir]) or
|
224
|
+
'lib' != File.basename(prefix) then
|
225
|
+
nil
|
226
|
+
else
|
227
|
+
File.dirname prefix
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
##
|
232
|
+
# Set the Gem home directory (as reported by Gem.dir).
|
233
|
+
|
234
|
+
def self.set_home(home)
|
235
|
+
home = home.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
236
|
+
@gem_home = home
|
237
|
+
ensure_gem_subdirectories(@gem_home)
|
238
|
+
end
|
239
|
+
|
240
|
+
private_class_method :set_home
|
241
|
+
|
242
|
+
##
|
243
|
+
# Set the Gem search path (as reported by Gem.path).
|
244
|
+
|
245
|
+
def self.set_paths(gpaths)
|
246
|
+
if gpaths
|
247
|
+
@gem_path = gpaths.split(File::PATH_SEPARATOR)
|
248
|
+
|
249
|
+
if File::ALT_SEPARATOR then
|
250
|
+
@gem_path.map! do |path|
|
251
|
+
path.gsub File::ALT_SEPARATOR, File::SEPARATOR
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
@gem_path << Gem.dir
|
256
|
+
else
|
257
|
+
# TODO: should this be Gem.default_path instead?
|
258
|
+
@gem_path = [Gem.dir]
|
259
|
+
end
|
260
|
+
|
261
|
+
@gem_path.uniq!
|
262
|
+
@gem_path.each do |gp| ensure_gem_subdirectories(gp) end
|
263
|
+
end
|
264
|
+
|
265
|
+
private_class_method :set_paths
|
266
|
+
|
267
|
+
##
|
268
|
+
# Glob pattern for require-able path suffixes.
|
269
|
+
|
270
|
+
def self.suffix_pattern
|
271
|
+
@suffix_pattern ||= "{#{suffixes.join(',')}}"
|
272
|
+
end
|
273
|
+
|
274
|
+
##
|
275
|
+
# Suffixes for require-able paths.
|
276
|
+
|
277
|
+
def self.suffixes
|
278
|
+
['', '.rb', '.rbw', '.so', '.bundle', '.dll', '.sl', '.jar']
|
279
|
+
end
|
280
|
+
|
281
|
+
##
|
282
|
+
# Use the +home+ and +paths+ values for Gem.dir and Gem.path. Used mainly
|
283
|
+
# by the unit tests to provide environment isolation.
|
284
|
+
|
285
|
+
def self.use_paths(home, paths=[])
|
286
|
+
clear_paths
|
287
|
+
set_home(home) if home
|
288
|
+
set_paths(paths.join(File::PATH_SEPARATOR)) if paths
|
289
|
+
end
|
290
|
+
|
291
|
+
##
|
292
|
+
# The home directory for the user.
|
293
|
+
|
294
|
+
def self.user_home
|
295
|
+
@user_home ||= find_home
|
296
|
+
end
|
297
|
+
|
298
|
+
end
|
299
|
+
|
300
|
+
module Config
|
301
|
+
# :stopdoc:
|
302
|
+
class << self
|
303
|
+
# Return the path to the data directory associated with the named
|
304
|
+
# package. If the package is loaded as a gem, return the gem
|
305
|
+
# specific data directory. Otherwise return a path to the share
|
306
|
+
# area as define by "#{ConfigMap[:datadir]}/#{package_name}".
|
307
|
+
def datadir(package_name)
|
308
|
+
Gem.datadir(package_name) ||
|
309
|
+
File.join(Gem::ConfigMap[:datadir], package_name)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
# :startdoc:
|
313
|
+
end
|
314
|
+
|
315
|
+
require 'rubygems/exceptions'
|
316
|
+
require 'rubygems/version'
|
317
|
+
require 'rubygems/requirement'
|
318
|
+
require 'rubygems/dependency'
|
319
|
+
|
320
|
+
begin
|
321
|
+
require 'rubygems/defaults/operating_system'
|
322
|
+
rescue LoadError
|
323
|
+
end
|
324
|
+
|
325
|
+
if defined?(RUBY_ENGINE) then
|
326
|
+
begin
|
327
|
+
require "rubygems/defaults/#{RUBY_ENGINE}"
|
328
|
+
rescue LoadError
|
329
|
+
end
|
330
|
+
end
|
@@ -104,6 +104,8 @@ module Gem
|
|
104
104
|
File.open(install_path, 'w') do |f|
|
105
105
|
f.write minigems_code.sub(placeholder, replacement)
|
106
106
|
end
|
107
|
+
minigems_dir = File.join(minigems_path, 'lib', 'minigems')
|
108
|
+
FileUtils.cp_r(minigems_dir, Gem::ConfigMap[:sitelibdir])
|
107
109
|
puts "Installed minigems at #{install_path}"
|
108
110
|
rescue Errno::EACCES
|
109
111
|
puts "Could not install minigems at #{install_path} (try sudo)"
|
@@ -113,8 +115,9 @@ module Gem
|
|
113
115
|
end
|
114
116
|
|
115
117
|
def remove_minigems!
|
118
|
+
minigems_dir = File.join(Gem::ConfigMap[:sitelibdir], 'minigems')
|
116
119
|
if File.exists?(install_path = File.join(Gem::ConfigMap[:sitelibdir], 'minigems.rb'))
|
117
|
-
if FileUtils.rm(install_path)
|
120
|
+
if FileUtils.rm(install_path) && FileUtils.rm_rf(minigems_dir)
|
118
121
|
puts "Succesfully removed #{install_path}"
|
119
122
|
return
|
120
123
|
end
|
data/spec/minigems_spec.rb
CHANGED
@@ -42,10 +42,6 @@ describe Gem::MiniGems do
|
|
42
42
|
Gem.available?("gem_with_lib", ">0.0.2").should be_false
|
43
43
|
end
|
44
44
|
|
45
|
-
it "should raise Gem::LoadError if no matching gem was found" do
|
46
|
-
lambda { gem("unknown_gem") }.should raise_error(Gem::LoadError)
|
47
|
-
end
|
48
|
-
|
49
45
|
it "uses 'gem' to setup additional load path entries" do
|
50
46
|
gem_lib_path = File.join(@gem_dir, "gems", "gem_with_lib-0.0.2", "lib")
|
51
47
|
gem_bin_path = File.join(@gem_dir, "gems", "gem_with_lib-0.0.2", "bin")
|
@@ -114,6 +110,14 @@ describe Gem::MiniGems do
|
|
114
110
|
# full rubygems library - which cannot really be undone!
|
115
111
|
# Comment out the specs above, including before/after setup.
|
116
112
|
#
|
113
|
+
# Also, use the system-installed minigems (for FULL_RUBYGEMS_METHODS):
|
114
|
+
#
|
115
|
+
# require 'minigems'
|
116
|
+
|
117
|
+
# it "should raise Gem::LoadError if no matching gem was found" do
|
118
|
+
# lambda { gem("unknown_gem") }.should raise_error(Gem::LoadError)
|
119
|
+
# end
|
120
|
+
|
117
121
|
# it "should load full rubygems if an unimplemented method is called" do
|
118
122
|
# # will only work if pre-installed minigems.rb is used!
|
119
123
|
# # so use: require 'minigems'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minigems
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabien Franzen
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-10-02 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- README
|
28
28
|
- Rakefile
|
29
29
|
- lib/minigems
|
30
|
+
- lib/minigems/core.rb
|
30
31
|
- lib/minigems/executable_wrapper
|
31
32
|
- lib/minigems/script_helper.rb
|
32
33
|
- lib/minigems.rb
|
@@ -79,7 +80,6 @@ files:
|
|
79
80
|
- spec/minigems_spec.rb
|
80
81
|
has_rdoc: true
|
81
82
|
homepage: http://merbivore.com
|
82
|
-
minigems: false
|
83
83
|
post_install_message: Run 'minigem' for instructions on how to proceed.
|
84
84
|
rdoc_options: []
|
85
85
|
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
requirements: []
|
101
101
|
|
102
102
|
rubyforge_project: merb
|
103
|
-
rubygems_version: 1.
|
103
|
+
rubygems_version: 1.3.0
|
104
104
|
signing_key:
|
105
105
|
specification_version: 2
|
106
106
|
summary: Lighweight drop-in replacement for rubygems.
|