faster_gem_script 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,49 +1,53 @@
1
- <<<<<<< HEAD
2
- This is a utility to speedup gem scripts quite a bit (especially for windows users), by avoiding expensive rubygems calls.
1
+ This is a utility to speedup gem executable scripts quite a bit (especially for windows users), by avoiding expensive rubygems calls.
3
2
 
4
3
  Background:
5
4
 
6
5
  By default rubygems runs a
7
6
 
8
- require rubygems
9
- ...
10
- load Gem.bin_path(...)
11
7
 
12
- in every gem's auto-generated startup script (ex: the ruby-prof gem has a ruby-prof command--it runs the above before running that command).
8
+ require rubygems
9
+ ...
10
+ load Gem.bin_path(name)
13
11
 
14
- This is great if you have a complex gem that requires specific version of its dependencies, etc.
12
+ in every gem's auto-generated startup (ex: bin/ruby-prof script).
15
13
 
16
- However, these calls result in an extra slowdown--especially in windows it can take up to an extra 2s, EVERY TIME, at startup.
14
+ This is great if you have a complex gem that requires specific version of its dependencies, etc.
17
15
 
18
- This can be alleviated, however, with this gem.
16
+ However, this template loads full rubygems (even in 1.9), which results in an extra slowdown.
17
+ In windows, for example, this take an extra 2s, EVERY TIME, at startup.
19
18
 
20
- In my box 2s went down to 0.37s (1.9.1 mingw). In linux it can speedup a tidge, too (from 0.3 to 0.16s).
19
+ This can be alleviated, however.
21
20
 
22
- How it does it:
21
+ In my box 2s went down to 0.37s (1.9.1 mingw). In linux it can startup a bit faster, too (from 0.3 to 0.16s).
23
22
 
24
- This gem provides a utility to replace the auto-generated startup script with one that caches the bin_path location so that the second/third/fourth times it starts up almost instantly.
23
+ This gem provides a utility to replace the auto-generated startup script with one that caches the
24
+ Gem.bin_path result so that the second/third/fourth times it starts up using a cached value.
25
25
 
26
- This works in 1.9 because of gem_prelude (which makes loading rubygems at times unnecessary), and of the "faster_rubygems" gem for 1.8.x, which is essentially gem_prelude for 1.8.
26
+ In 1.9, this allows it to avoid loading full rubygems.
27
+ In 1.8, it relies on the "faster_rubygems" gem, which also avoids loading full rubygems.
27
28
 
28
29
  How to use it:
29
30
 
30
- # install a gem that has a command line executable, like ruby-prof
31
-
32
- # install a gem pre-req--necessary because of a bug in rubygems
33
- C:> gem install os
34
- # install the optimizer
31
+ # install the gem
35
32
  C:> gem install faster_gem_scripts
36
- # this next line will change based on your ruby location
37
- C:> faster_gem_script c:\ruby18\bin\whichr
33
+ # now use it to optimize an existing gem, ex:
34
+ C:> faster_gem_script c:\ruby18\bin\redcar
35
+
36
+ If you want an easy way to discover the gem paths (and are on windows),
37
+ you can checkout the whichr gem (http://github.com/rdp/whichr).
38
+
39
+ Other caveat: if your gem has any "complex dependencies" ,like it uses things like
38
40
 
39
- If you want an easier way to discover the path for your commands (and are on windows), you can checkout the whichr gem (http://github.com/rdp/whichr).
41
+ gem 'some_other_dependency', '= 1.1.9' # somewhere inside it
40
42
 
41
- Caveat: If you update a gem after using this, you'll need to run it again so that it will be sure to cache the location of the latest version of the gem.
43
+ then this system won't help, because it will be forced to load full rubygems at that point.
42
44
 
43
- Other caveat: if your gem has any "complex dependencies" (like it uses the gem command like
45
+ You can find out by running it once. If it fails then reinstall the gem in question to get back to its original functionality.
44
46
 
45
- gem 'some_other_dependency', '= 1.1.9'
47
+ Current problems:
46
48
 
47
- then this system won't work for you. Try it out to see.
49
+ Currently it only works for executables named the same thing as their gem is, ex:
50
+ redcar's bin/redcar works
51
+ redcar's bin/cucumber does not.
48
52
 
49
- You can find out by running it once. If it fails then reinstall the gem to get back to its original functionality.
53
+ Try it out and see. If it fails then reinstall the gem in question to get back to its original functionality.
data/Rakefile CHANGED
@@ -10,4 +10,4 @@
10
10
  gemspec.add_development_dependency('rspec')
11
11
  # don't need faster_rubygems here, as we auto install it
12
12
  gemspec.extensions = 'ext/mkrf_conf.rb'
13
- end
13
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.2
@@ -2,8 +2,9 @@
2
2
  require 'faster_gem_scripts'
3
3
  if ARGV.length == 1
4
4
  FasterGemScripts.overwrite ARGV[0]
5
+ puts 'clearing caches because of new gem install'
5
6
  else
6
7
  puts 'syntax: script_name_to_optimize (clears caches either way)'
7
8
  end
9
+ FasterGemScripts.clear_caches!
8
10
 
9
- FasterGemScripts.clear_caches!
@@ -1,27 +1,25 @@
1
+ require 'sane'
1
2
 
2
3
  class FasterGemScripts
4
+
3
5
  def self.overwrite full_path
4
- contents_should_be = File.read File.dirname(__FILE__) + '/template'
5
- if File.file?(full_path)
6
- puts 'faster_gem_scripts: optimizing ' + full_path + '...'
7
- File.open(full_path, 'wb') do |f| f.write(contents_should_be); end
8
- bin_loc = full_path + '_bin_location'
9
- File.delete(bin_loc) if File.exist?(bin_loc)
10
- else
11
- puts "unable to find the binary:" + full_path + " you may want to find it and overwrite it yourself using C:\>faster_gem_script file_name (no .bat)"
12
- end
6
+ contents_should_be = File.read File.dirname(__FILE__) + '/template'
7
+ if File.file?(full_path)
8
+ puts 'faster_gem_scripts: optimizing ' + full_path + '...'
9
+ File.open(full_path, 'wb') do |f| f.write(contents_should_be); end
10
+ bin_loc = full_path + '_bin_location'
11
+ File.delete(bin_loc) if File.exist?(bin_loc)
12
+ else
13
+ puts "unable to find the binary:" + full_path + " you may want to find it and overwrite it yourself using C:\>faster_gem_script file_name (no .bat)"
14
+ end
13
15
  end
14
16
 
15
17
  def self.clear_caches!
16
- # I only know about one type...
17
- bin_dir = Gem.ruby.split('/')[0..-2].join('/') # strip off ruby.exe
18
- require 'ruby-debug'
19
- # debugger
18
+ bin_dir = File.dirname(OS.ruby_bin)
20
19
  Dir[bin_dir + '/*_bin_location'].each{|file|
21
- puts 'faster_gem_scripts clearing cached file ' + file
20
+ puts 'faster_gem_scripts clearing previously cached file ' + file
22
21
  File.delete file
23
- }
24
-
22
+ }
25
23
  end
26
24
 
27
25
  end
@@ -0,0 +1,24 @@
1
+ Gem.post_install { |gem_installer_instance|
2
+ puts 'clearing faster_gem script because of install'
3
+ require 'faster_gem_scripts'
4
+ FasterGemScripts.clear_caches!
5
+
6
+
7
+ # all = gem_installer_instance.spec.files.select{|file| file =~ /^bin/ }
8
+ # bin_dir = Gem.ruby.split('/')[0..-3].join('/')
9
+ # if all.length > 0
10
+ # FasterGemScripts.clear_caches!
11
+ # all.each{|script_name|
12
+ # name = bin_dir + '/' + script_name
13
+ # FasterGemScripts.overwrite name
14
+ # }
15
+ # end
16
+ }
17
+
18
+ Gem.post_uninstall { |gem_installer_instance|
19
+ if (gem_installer_instance.spec.files.select{|file| file =~ /^bin/ }.length > 0)
20
+ puts 'clearing faster_gem script because of uninstall'
21
+ require 'faster_gem_scripts'
22
+ FasterGemScripts.clear_caches!
23
+ end
24
+ }
@@ -25,7 +25,7 @@ describe "rewriter" do
25
25
  end
26
26
 
27
27
  it "should clear olds on request" do
28
- old_file = File.dirname(OS.ruby_bin) + '/yo_bin_location'
28
+ old_file = File.dirname(OS.ruby_bin) + '/yo_bin_location'
29
29
  FileUtils.touch old_file
30
30
  ARGV << 'yoyo'
31
31
  load __dir__ + '/../bin/faster_gem_script'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faster_gem_script
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 2
10
+ version: 0.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roger Pack
@@ -16,7 +16,7 @@ bindir: bin
16
16
  cert_chain: []
17
17
 
18
18
  date: 2010-06-07 00:00:00 -06:00
19
- default_executable:
19
+ default_executable: faster_gem_script
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: sane
@@ -66,7 +66,6 @@ description:
66
66
  email: rogerdpack@gmail.com
67
67
  executables:
68
68
  - faster_gem_script
69
- - yo_bin_location
70
69
  extensions:
71
70
  - ext/mkrf_conf.rb
72
71
  extra_rdoc_files:
@@ -78,10 +77,9 @@ files:
78
77
  - bin/faster_gem_script
79
78
  - ext/mkrf_conf.rb
80
79
  - lib/faster_gem_scripts.rb
81
- - lib/rubygems_plugin.rb.disabled
80
+ - lib/rubygems_plugin.rb
82
81
  - lib/template
83
82
  - spec/spec.faster_gem_scripts.rb
84
- - bin/yo_bin_location
85
83
  has_rdoc: true
86
84
  homepage: http://github.com/rdp/faster_gem_scripts
87
85
  licenses: []
data/bin/yo_bin_location DELETED
File without changes
@@ -1,18 +0,0 @@
1
- Gem.post_install { |gem_installer_instance|
2
- require 'faster_gem_scripts'
3
- all = gem_installer_instance.spec.files.select{|file| file =~ /^bin/ }
4
- bin_dir = Gem.ruby.split('/')[0..-3].join('/')
5
- if all.length > 0
6
- FasterGemScripts.clear_caches!
7
- all.each{|script_name|
8
- name = bin_dir + '/' + script_name
9
- FasterGemScripts.overwrite name
10
- }
11
- end
12
- }
13
-
14
- Gem.post_uninstall { |gem_installer_instance|
15
- require 'faster_gem_scripts'
16
- require 'sane'
17
- FasterGemScripts.clear_caches! if (gem_installer_instance.spec.files.select{|file| file =~ /^bin/ }.length > 0)
18
- }