gem-cache 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/gem/cache.rb +28 -0
- data/lib/rubygems/commands/cache_command.rb +48 -0
- data/lib/rubygems_plugin.rb +15 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eec2346676d7e841a58259cb9f52ec2fd06bd272
|
4
|
+
data.tar.gz: 98c98397f3c5772fd29b9d6c1527bfe88e695e9a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f4dc19ed1dcfe1558a5e8ba04e4006857f030b163ea984597cc0e7c6ec0a8035c011cb6556fd533baddff55fa97fc1ec2bb469f29e95e0557197da70370ed0d
|
7
|
+
data.tar.gz: e5798106c4ba94e0580e12090cbe8a3bf62f1dc08d4cb6281210a3d841193c9e7ae070a227850cb003815c87a8cbb417b617c4134bf18cabb4dd2492612b115f
|
data/lib/gem/cache.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "trie"
|
2
|
+
|
3
|
+
module Gem::LoadCache
|
4
|
+
Trie = Struct.new(:trie, :values) do
|
5
|
+
def get(x)
|
6
|
+
value = trie.get(x)
|
7
|
+
return value ? values[value] : nil
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.set(path)
|
12
|
+
TRIE.trie = Trie.read(path)
|
13
|
+
TRIE.values = Marshal.load(File.read "#{path}.list")
|
14
|
+
end
|
15
|
+
|
16
|
+
TRIE = Trie.new
|
17
|
+
end
|
18
|
+
|
19
|
+
alias __require__ require
|
20
|
+
|
21
|
+
def require(str)
|
22
|
+
unless Gem::LoadCache::TRIE.trie
|
23
|
+
path = File.expand_path("~/.gem/cache")
|
24
|
+
Gem::LoadCache::TRIE.trie = Trie.read(path)
|
25
|
+
Gem::LoadCache::TRIE.values = Marshal.load(File.read "#{path}.list")
|
26
|
+
end
|
27
|
+
__require__ Gem::LoadCache::TRIE.get(str) || str
|
28
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "trie"
|
2
|
+
|
3
|
+
class Gem::Commands::CacheCommand < Gem::Command
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
super 'cache', 'Cache your current path for fast loading'
|
7
|
+
|
8
|
+
add_option('-p', '--path PATH', 'Path to use instead of the default, separated by `:\'') do |value,options|
|
9
|
+
$:.replace value.split(':')
|
10
|
+
end
|
11
|
+
|
12
|
+
add_option('-d', '--with-dir DIR', 'Directory that should be included in the cache') do |dir,options|
|
13
|
+
$:.unshift dir
|
14
|
+
end
|
15
|
+
|
16
|
+
add_option('-o', '--output-file FILE', 'The file in which the cache is placed') do |f,options|
|
17
|
+
options[:output] = f
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def description
|
22
|
+
'A RubyGems plugin that takes an image of your gem structure and caches it to allow for a faster require time.'
|
23
|
+
end
|
24
|
+
|
25
|
+
def usage
|
26
|
+
"#{program_name} [-p PATH] [-d DIR]"
|
27
|
+
end
|
28
|
+
|
29
|
+
def execute
|
30
|
+
options[:output] ||= File.expand_path("~/.gem/cache")
|
31
|
+
puts "Caching gem structure"
|
32
|
+
tree = Trie.new; names = []; i = 0
|
33
|
+
$:.each do |dir|
|
34
|
+
(Dir["#{dir}/*.rb"] + Dir["#{dir}/lib/**/*.rb"]).each do |file|
|
35
|
+
names << file
|
36
|
+
tree.add file[dir.size+1..-4], i
|
37
|
+
i += 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
File.open(options[:output]+".list", File::CREAT|File::TRUNC|File::RDWR) do |f|
|
42
|
+
f.write Marshal.dump names
|
43
|
+
end
|
44
|
+
|
45
|
+
tree.save(options[:output])
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.3.6')
|
2
|
+
require "rubygems/command_manager"
|
3
|
+
Gem::CommandManager.instance.register_command(:cache)
|
4
|
+
end
|
5
|
+
|
6
|
+
|
7
|
+
module Gem
|
8
|
+
post_install do |gem_installer|
|
9
|
+
Gem::CommandManager.instance[:cache].invoke
|
10
|
+
end
|
11
|
+
|
12
|
+
post_uninstall do |gem_installer|
|
13
|
+
Gem::CommandManager.instance[:cache].invoke
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gem-cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Carey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fast_trie
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Cache your path to speed up require time
|
28
|
+
email: matthew.b.carey@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/gem/cache.rb
|
34
|
+
- lib/rubygems/commands/cache_command.rb
|
35
|
+
- lib/rubygems_plugin.rb
|
36
|
+
homepage: http://github.com/swarley/
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.3.6
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.0.0.rc.2
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: A gem plugin to cache your path
|
60
|
+
test_files: []
|
61
|
+
has_rdoc:
|