faster_rubygems 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'jeweler'
2
+ Jeweler::Tasks.new do |s|
3
+ s.name = %q{faster_rubygems}
4
+
5
+
6
+ s.summary = %q{faster gem loading}
7
+ s.extensions = ["ext/mkrf_conf.rb"]
8
+
9
+ s.post_install_message = "
10
+
11
+ installed! use -> require 'faster_rubygems'
12
+
13
+ "
14
+
15
+ s.add_development_dependency 'test-unit', '=1.2.3'
16
+ s.add_development_dependency 'test-unit', '=2.0.6'
17
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.2.0
data/install.rb CHANGED
@@ -9,4 +9,4 @@ end
9
9
 
10
10
  require 'frubygems' # test it out now :P
11
11
 
12
- puts 'Installed--thank you for trying out -- require \'frubygems\''
12
+ puts 'Installed--thank you for trying out -- require \'faster_rubygems\''
@@ -1,58 +1,28 @@
1
1
  if RUBY_VERSION < '1.9'
2
- require 'rbconfig'
3
-
4
- gem_paths = []
5
- gem_paths << Config::CONFIG['libdir'] + '/ruby/gems/' + RUBY_VERSION[0..2] + '/gems'
6
-
7
- # handle ~/.gem
8
- gem_paths << File.expand_path('~') + '/.gem/ruby/' + RUBY_VERSION[0..2] + '/gems'
9
-
10
- # handle ENV['GEM_PATH'] if it exists
11
- gem_paths << ENV['GEM_PATH'].split(':').select{|path| path + '/.gems'} if ENV['GEM_PATH'] # TODO should this override or supplement?
12
-
13
- # TODO
14
- # spec: should find highest version of files
15
- # spec: with multiple paths should find all files :P
16
-
17
- all_gems = []
18
-
19
- for gem_path in gem_paths.flatten do
20
-
21
- all_gems << Dir.glob(gem_path + '/*')
22
-
2
+ require File.dirname(__FILE__) + '/faster_rubygems_lib.rb'
3
+ all = FasterRubyGems.gem_prelude_paths
4
+ all.each{|path|
5
+ $: << path
6
+ }
7
+
8
+ module Kernel
9
+
10
+ def gem *args
11
+ undef :gem
12
+ require 'rubygems' # punt!
13
+ gem *args
14
+ end
15
+
23
16
  end
24
- all_gems.flatten!.sort!.reverse!
25
-
26
- already_loaded_gems = {}
27
-
28
- for gem in all_gems do
29
-
30
- version = gem.split('-')[-1]
31
- if version =~ /\d+\.\d+\.\d+/
32
- name = gem.split('-')[0..-2]
33
- else
34
- gem =~ /(.*)(\d+\.\d+\.\d+).*$/ # like abc-1.2.3-mswin32-60 or what not
35
- version = $2
36
- name = $1
37
- next unless version # a few oddities like rbfind-1.1
17
+
18
+ module ::Gem
19
+ def self.const_missing const
20
+ require 'rubygems' # punt!
21
+ return Gem.const_get(const)
38
22
  end
39
-
40
- if(!already_loaded_gems[name])
41
- already_loaded_gems[name] = true
42
- if File.directory? gem + '/lib'
43
- $: << gem + '/lib'
44
- else
45
- # unfortunately a few gems load from, say gem/something_not_lib/gemname.rb
46
- for dir in Dir.glob(gem + '/*') do
47
- if File.directory? dir
48
- $: << dir
49
- # if anybody wants anything lower than that, let me know
50
- end
51
- end
52
- end
53
- end
54
-
55
23
  end
24
+
25
+
56
26
  else
57
27
  # not needed in 1.9, which by default loads gem_prelude
58
28
  end
@@ -0,0 +1,64 @@
1
+ class FasterRubyGems
2
+ def self.gem_prelude_paths
3
+ # note: the RUBY_VERSION[0..2] thing below fails for 1.9...
4
+ raise 'bad version' if RUBY_VERSION[0..2] > '1.8'
5
+ require 'rbconfig'
6
+
7
+ gem_paths = []
8
+ # add the default gem path
9
+
10
+ gem_paths << Config::CONFIG['libdir'] + '/ruby/gems/' + RUBY_VERSION[0..2] + '/gems'
11
+
12
+ # add ~/.gem
13
+ gem_paths << File.expand_path('~') + '/.gem/ruby/' + RUBY_VERSION[0..2] + '/gems'
14
+
15
+ # add ENV['GEM_PATH'] if it exists
16
+ if ENV['GEM_PATH']
17
+ gem_paths = ENV['GEM_PATH'].split(File::PATH_SEPARATOR).collect{|path| path + '/gems'}
18
+ end
19
+
20
+ all_gems = []
21
+
22
+ for gem_path in gem_paths.flatten do
23
+ all_gems << Dir.glob(gem_path + '/*')
24
+ end
25
+ all_gems.flatten!
26
+ all_gems = all_gems.sort_by{|gem| gem.split('-')[-1].split('.').map{|n| n.to_i}} # 0.10.0 > 0.9.0 so straight sort won't work for us
27
+ all_gems.reverse!
28
+
29
+ already_loaded_gems = {}
30
+
31
+ prelude_paths = []
32
+
33
+ for gem in all_gems do
34
+
35
+ version = gem.split('-')[-1]
36
+ if version =~ /\d+\.\d+\.\d+/
37
+ name = gem.split('-')[0..-2]
38
+ else
39
+ gem =~ /(.*)(\d+\.\d+\.\d+).*$/ # like abc-1.2.3-mswin32-60 or what not
40
+ version = $2
41
+ name = $1
42
+ next unless version # a few oddities like rbfind-1.1
43
+ end
44
+
45
+ if(!already_loaded_gems[name])
46
+ already_loaded_gems[name] = true
47
+ if File.directory? gem + '/lib'
48
+ prelude_paths << gem + '/lib'
49
+ else
50
+ # unfortunately a few gems load from, say gem/something_not_lib/gemname.rb
51
+ for dir in Dir.glob(gem + '/*') do
52
+ if File.directory? dir
53
+ $: << dir
54
+ # if anybody wants anything lower than that, let me know
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ end
61
+ prelude_paths
62
+ end
63
+ end
64
+
@@ -0,0 +1,55 @@
1
+ require 'rubygems' if RUBY_VERSION[0..2] < '1.9'
2
+ require 'sane'
3
+ require_relative '../lib/faster_rubygems_lib'
4
+ require 'spec/autorun'
5
+ require 'fileutils'
6
+
7
+ describe FasterRubyGems do
8
+
9
+ before do
10
+ ENV['GEM_PATH'] = 'test_dir'
11
+ @gem_path = 'test_dir/gems/' # boo
12
+ FileUtils.rm_rf @gem_path
13
+ raise 'you dont need to test this on 1.9' if RUBY_VERSION > '1.9'
14
+ end
15
+
16
+ it "should calculate something" do
17
+ paths = FasterRubyGems.gem_prelude_paths
18
+ assert paths.length == 0
19
+ FileUtils.mkdir_p @gem_path + '/abc-0.9.0/lib'
20
+ paths = FasterRubyGems.gem_prelude_paths
21
+ assert paths.length == 1
22
+ end
23
+
24
+ it "should calculate 0.10.0 as greater than 0.9.0" do
25
+
26
+ FileUtils.mkdir_p @gem_path + '/abc-0.9.0/lib'
27
+ FileUtils.mkdir_p @gem_path + '/abc-0.10.0/lib'
28
+ paths = FasterRubyGems.gem_prelude_paths
29
+ assert( (paths.grep /abc-0.10.0/).length > 0)
30
+ end
31
+
32
+ it "should find highest version of normal numbered gems" do
33
+ FileUtils.mkdir_p @gem_path + '/abc-0.8.0/lib'
34
+ FileUtils.mkdir_p @gem_path + '/abc-0.9.0/lib'
35
+ paths = FasterRubyGems.gem_prelude_paths
36
+ assert( (paths.grep /abc-0.9.0/).length > 0)
37
+ end
38
+
39
+ it "with multiple paths should find all files"
40
+
41
+ it "should respect file::separator"
42
+
43
+
44
+ def ruby lib
45
+ assert system(OS.ruby_bin + ' ' + lib)
46
+ assert system(OS.ruby_bin + ' ' + lib)
47
+ end
48
+
49
+ it "should load full rubygems on gem xxx" do
50
+ ruby('files/test_gem.rb')
51
+ ruby('files/test_gem_const.rb')
52
+
53
+ end
54
+
55
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faster_rubygems
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-29 00:00:00 -06:00
12
+ date: 2009-12-28 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -23,14 +23,17 @@ extra_rdoc_files:
23
23
  - README
24
24
  files:
25
25
  - README
26
+ - Rakefile
26
27
  - VERSION
27
28
  - examples/require_fast_start.rb
28
29
  - examples/require_rubygems_normal.rb
29
30
  - ext/mkrf_conf.rb
30
31
  - install.rb
32
+ - lib/faster_rubygems.rb
33
+ - lib/faster_rubygems_lib.rb
31
34
  - lib/frubygems.rb
32
35
  - lib/ubygemsf.rb
33
- - lib/faster_rubygems.rb
36
+ - spec/spec.faster_rubygems.rb
34
37
  has_rdoc: true
35
38
  homepage:
36
39
  licenses: []
@@ -38,7 +41,7 @@ licenses: []
38
41
  post_install_message: |+
39
42
 
40
43
 
41
- installed! require 'frubygems' now
44
+ installed! use by doing require 'faster_rubygems'
42
45
 
43
46
  rdoc_options:
44
47
  - --charset=UTF-8
@@ -64,5 +67,6 @@ signing_key:
64
67
  specification_version: 3
65
68
  summary: faster gem loading
66
69
  test_files:
70
+ - spec/spec.faster_rubygems.rb
67
71
  - examples/require_fast_start.rb
68
72
  - examples/require_rubygems_normal.rb