xgem 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/bin/xgem +72 -0
  2. data/bin/xgem-ruby +3 -0
  3. data/data/.keep +0 -0
  4. data/lib/xgem.rb +46 -0
  5. metadata +50 -0
data/bin/xgem ADDED
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ xgem_root = File.expand_path("#{File.expand_path(__FILE__)}/../..")
4
+
5
+ commands = {
6
+ "refresh" => -> {
7
+ require "fileutils"
8
+
9
+ puts "Refreshing xgem cache..."
10
+ total = Gem::Specification.count
11
+ current = 0
12
+ suffixes = Gem.suffixes.map { |s| Regexp.new("#{Regexp.escape s}\\z") }
13
+ require_map = {}
14
+
15
+ print "0/#{total}"
16
+
17
+ Gem::Specification.each do |spec|
18
+ spec.require_paths.each do |require_path|
19
+ root = "#{spec.full_gem_path}/#{require_path}/"
20
+ Dir["#{root}**/*"].each do |file|
21
+ if File.file? file
22
+ suffixes.each do |suffix|
23
+ if file =~ suffix
24
+ require_map[file[root.size..-1].gsub(suffix, "")] = file.gsub(suffix, "")
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ print "\r#{current += 1}/#{total}"
31
+ end
32
+
33
+ File.write "#{xgem_root}/data/require_paths", Marshal.dump(require_map)
34
+ puts "\rReady to rock and roll!"
35
+ },
36
+
37
+ "install" => -> {
38
+ print "Installing xgem-ruby executable... "
39
+
40
+ File.write "#{$0}-ruby", <<-XGEM_RUBY.gsub(/^ /,"")
41
+ #!/bin/bash
42
+
43
+ xgem_root="#{__FILE__.inspect[1...-1]}/../.."
44
+
45
+ ruby --disable-gems -I "$xgem_root/lib" -r xgem $@
46
+ XGEM_RUBY
47
+
48
+ puts "ok!"
49
+
50
+ commands["refresh"].call
51
+ }
52
+ }
53
+
54
+ if commands[ARGV.first]
55
+ commands[ARGV.first].call
56
+ else
57
+ puts <<-USAGE.gsub(/^ /,"")
58
+ Usage: xgem <command>
59
+
60
+ Available commands are:
61
+
62
+ refresh - Scans all installed gems and adds them to the require path
63
+ cache. You will need to run 'xgem refresh' every time you
64
+ install or uninstall a gem.
65
+
66
+ install - You must run 'xgem install' when you first install xgem in
67
+ order to use the 'xgem-ruby' command. Note that this will not
68
+ modify your system in any way that isn't undoable by running
69
+ 'gem uninstall xgem'.
70
+
71
+ USAGE
72
+ end
data/bin/xgem-ruby ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env
2
+
3
+ puts "Please run 'xgem install' and try again."
data/data/.keep ADDED
File without changes
data/lib/xgem.rb ADDED
@@ -0,0 +1,46 @@
1
+ module XGem
2
+ ROOT = File.expand_path "#{File.expand_path(__FILE__)}/../.."
3
+
4
+ def self.resolve_require_path(path)
5
+ @require_paths ||= Marshal.load(File.open("#{ROOT}/data/require_paths", "rb") { |f| f.read })
6
+ @require_paths[path]
7
+ end
8
+
9
+ def self.resolve_autoload_path(path)
10
+ if xgem_path = resolve_require_path(path)
11
+ Gem.suffixes.each do |suffix|
12
+ return "#{xgem_path}#{suffix}" if File.file? "#{xgem_path}#{suffix}"
13
+ end
14
+ end
15
+ path
16
+ end
17
+
18
+ def self.require(path)
19
+ __xgem_original_require resolve_require_path(path) || path
20
+ end
21
+ end
22
+
23
+ module Kernel
24
+ # save the pristine require *BEFORE* loading rubygems so we don't have to go
25
+ # through its slow path...
26
+ alias :__xgem_original_require :require
27
+ alias :__xgem_original_autoload :autoload
28
+
29
+ require "rubygems"
30
+
31
+ def require(path)
32
+ XGem.require path
33
+ end
34
+
35
+ def autoload(symbol, path)
36
+ __xgem_original_autoload symbol, XGem.resolve_autoload_path(path)
37
+ end
38
+ end
39
+
40
+ class Module
41
+ alias :__xgem_original_autoload :autoload
42
+
43
+ def autoload(symbol, path)
44
+ __xgem_original_autoload symbol, XGem.resolve_autoload_path(path)
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xgem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Charlie Somerville
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-18 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email:
16
+ executables:
17
+ - xgem
18
+ - xgem-ruby
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - bin/xgem
23
+ - bin/xgem-ruby
24
+ - lib/xgem.rb
25
+ - data/.keep
26
+ homepage: https://github.com/charliesome/xgem
27
+ licenses: []
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 1.8.24
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: A very tiny shim that dramatically speeds up gem requires
50
+ test_files: []