Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Backported some features from the pending rubygems patch

  • Loading branch information...
commit eb41d4d4f12d1080907a00719a03c5eb2681441e 1 parent ba97251
Fabien Franzen authored
2  bin/minigem
View
@@ -58,7 +58,7 @@ elsif ARGV[0] == 'prepare'
ARGV.shift # skip prepare command argument
ensure_in_load_path!(ARGV.empty?)
ARGV.each do |gem_name|
- next unless (gem_spec = Gem.source_index.search(gem_name).last)
+ next unless (gem_spec = Gem.source_index.find_name(gem_name).sort_by { |g| g.version }.last)
adapt_executables_for(gem_spec)
end
elsif ARGV[0] == 'install' || ARGV[0] == 'update'
80 lib/minigems.rb
View
@@ -2,54 +2,10 @@ module Gem
module MiniGems
VERSION = "0.0.1"
- FULL_RUBYGEMS_METHODS = %w[
- activate
- all_load_paths
- available?
- binary_mode
- bindir
- cache
- clear_paths
- config_file
- configuration
- configuration=
- datadir
- default_bindir
- default_dir
- default_exec_format
- default_path
- default_sources
- default_system_source_cache_dir
- default_user_source_cache_dir
- deflate
- dir
- ensure_gem_subdirectories
- gunzip
- gzip
- inflate
- latest_load_paths
- load_path_insert_index
- loaded_specs
- manage_gems
- marshal_version
- path
- platforms
- platforms=
- prefix
- read_binary
- refresh
- required_location
- ruby
- ruby_version
- searcher
- source_index
- sources
- suffix_pattern
- suffixes
- use_paths
- user_home
- win_platform?
- ]
+ # The next line needs to be kept exactly as shown; it's being replaced
+ # during minigems installation.
+ FULL_RUBYGEMS_METHODS = []
+
end
end
@@ -65,21 +21,6 @@ module MiniGems
require "rubygems/specification"
require "rbconfig"
- # Methods we're implementing, based on standard Gem but with our own logic
- # - Kernel#gem
- # - Kernel#require
- # - Gem.activate
- # - Gem.available?
- # - Gem.path
- # - Gem.default_path
- # - Gem.clear_paths
- # - Gem.refresh
- # - Gem.report_activate_error
-
- # Methods Gem prelude adds in addition to the standard methods
- # - Gem.latest_gem_paths
- # - Gem.minigems?
-
module Kernel
def gem(name, *versions)
@@ -115,18 +56,17 @@ def require(path) # :nodoc:
module Gem
+ CORE_GEM_METHODS = Gem.methods(false)
+
class Exception < RuntimeError; end
class LoadError < ::LoadError
attr_accessor :name, :version_requirement
end
- # Keep track of the rubygems 'mode'.
- @minigems = !Gem.const_defined?(:Builder)
-
# Whether minigems is being used or full rubygems has taken over.
def self.minigems?
- @minigems
+ not const_defined?(:SourceIndex)
end
# Keep track of loaded gems, maps gem name to full_name.
@@ -310,14 +250,12 @@ def self.report_activate_error(gem)
# Load the full rubygems suite, at which point all minigems logic
# is being overridden, so all regular methods and classes are available.
def self.load_full_rubygems!
- @minigems = false
- # Clear out any prelude methods
+ # Clear out any minigems methods
class << self
- Gem::MINIGEMS_METHODS.each do |method_name|
+ (MINIGEMS_METHODS - CORE_GEM_METHODS).each do |method_name|
undef_method method_name
end
end
-
# Re-alias the 'require' method back to its original.
::Kernel.module_eval { alias_method :require, :gem_original_require }
require $LOADED_FEATURES.delete("rubygems.rb")
8 lib/minigems/executable_wrapper
View
@@ -1,15 +1,11 @@
SHEBANG
-# This file was generated by MiniGems.
+# This file was generated by MiniGems (standalone version).
#
# The application 'EXECUTABLE_NAME' is installed as part of a gem (GEM_NAME),
# and this file is here to facilitate running it.
-begin
- require 'minigems'
-rescue LoadError
- require 'rubygems'
-end
+require 'minigems'
version = ">= 0"
11 lib/minigems/script_helper.rb
View
@@ -47,7 +47,7 @@ module ScriptHelper
def minigems_path
@minigems_path ||= begin
- if (gem_spec = Gem.source_index.search('minigems').last)
+ if (gem_spec = Gem.source_index.find_name('minigems').sort_by { |g| g.version }.last)
gem_spec.full_gem_path
else
raise "Minigems gem not found!"
@@ -74,7 +74,14 @@ def ensure_in_load_path!(force = false)
if force || !File.exists?(install_path)
if File.exists?(source_path = File.join(minigems_path, 'lib', 'minigems.rb'))
begin
- FileUtils.copy_file(source_path, install_path)
+ minigems_code = File.read(source_path)
+ placeholder = "FULL_RUBYGEMS_METHODS = []"
+ replacement = "FULL_RUBYGEMS_METHODS = %w[\n "
+ replacement << (Gem.methods - Object.methods).sort.join("\n ")
+ replacement << "\n ]"
+ File.open(install_path, 'w') do |f|
+ f.write minigems_code.sub(placeholder, replacement)
+ end
puts "Installed minigems at #{install_path}"
rescue Errno::EACCES
puts "Could not install minigems at #{install_path} (try sudo)"
Please sign in to comment.
Something went wrong with that request. Please try again.