bootscale 0.1.1 → 0.2.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 +4 -4
- data/README.md +9 -1
- data/bootscale.gemspec +2 -0
- data/lib/bootscale/cache_builder.rb +14 -0
- data/lib/bootscale/entry.rb +4 -8
- data/lib/bootscale/file_storage.rb +24 -0
- data/lib/bootscale/setup.rb +3 -3
- data/lib/bootscale/version.rb +1 -1
- data/lib/bootscale.rb +45 -6
- metadata +18 -3
- data/lib/bootscale/cache.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08516aaf7096d27483c2fb2585ccfcb8e391621b
|
4
|
+
data.tar.gz: f60f2071672f182b20fb27b0d198d4b5ea9e0f1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6671a28791b4c9f0876c5fd944798b72d9530c8d094768ea81bf217048100826854ed61edb6a046131188a6db40f692bfbf7d28f1078b647b047a183bbe5ac2
|
7
|
+
data.tar.gz: ab3afc79b67b5935522f84327565ce460912a88c9b0ad7047079072b647617a09695535687053ce28db6ef5d120a5c40004f13a0129616cc0c4b0016b334848a
|
data/README.md
CHANGED
@@ -14,7 +14,14 @@ And then execute:
|
|
14
14
|
|
15
15
|
$ bundle
|
16
16
|
|
17
|
-
Then you need to add
|
17
|
+
Then you need to add right after `require 'bundler/setup'`:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'bundler/setup'
|
21
|
+
require 'bootscale'
|
22
|
+
Bootscale.setup(cache_directory: '/path/to/cache/directory')
|
23
|
+
```
|
24
|
+
|
18
25
|
If your application is a Rails application, you will find this in `config/boot.rb`.
|
19
26
|
|
20
27
|
### Important
|
@@ -46,3 +53,4 @@ but for bigger applications (300+ gems) it can make the application boot up to 3
|
|
46
53
|
|
47
54
|
Bug reports and pull requests are welcome on GitHub at https://github.com/byroot/bootscale.
|
48
55
|
|
56
|
+
Thanks to Aaron Patterson for the idea of converting relative paths to absolute paths.
|
data/bootscale.gemspec
CHANGED
@@ -17,5 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.bindir = 'exe'
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ['lib']
|
20
|
+
|
20
21
|
spec.required_ruby_version = '>= 1.9.3'
|
22
|
+
spec.add_runtime_dependency 'msgpack', '~> 0.6.2'
|
21
23
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Bootscale
|
2
|
+
class CacheBuilder
|
3
|
+
attr_reader :entries
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@entries = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate(load_path)
|
10
|
+
ordered_entries = load_path.map { |path| entries.fetch(path) { entries[path] = Entry.new(path) } }
|
11
|
+
Hash[ordered_entries.reverse.flat_map(&:features)]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/bootscale/entry.rb
CHANGED
@@ -1,13 +1,9 @@
|
|
1
1
|
module Bootscale
|
2
|
-
DL_EXTENSIONS = [
|
3
|
-
RbConfig::CONFIG['DLEXT'],
|
4
|
-
RbConfig::CONFIG['DLEXT2'],
|
5
|
-
].reject(&:empty?).map { |ext| ".#{ext}"}
|
6
|
-
|
7
|
-
DOT_SO = '.so'.freeze
|
8
|
-
DOT_RB = '.rb'.freeze
|
9
|
-
|
10
2
|
class Entry
|
3
|
+
DL_EXTENSIONS = [
|
4
|
+
RbConfig::CONFIG['DLEXT'],
|
5
|
+
RbConfig::CONFIG['DLEXT2'],
|
6
|
+
].reject(&:empty?).map { |ext| ".#{ext}"}
|
11
7
|
FEATURE_FILES = "**/*{#{DOT_RB},#{DL_EXTENSIONS.join(',')}}"
|
12
8
|
NORMALIZE_NATIVE_EXTENSIONS = !DL_EXTENSIONS.include?(DOT_SO)
|
13
9
|
ALTERNATIVE_NATIVE_EXTENSIONS_PATTERN = /\.(o|bundle|dylib)\z/
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
require 'msgpack'
|
3
|
+
|
4
|
+
module Bootscale
|
5
|
+
class FileStorage
|
6
|
+
def initialize(directory)
|
7
|
+
@directory = directory
|
8
|
+
end
|
9
|
+
|
10
|
+
def load(load_path)
|
11
|
+
path = cache_path(load_path)
|
12
|
+
MessagePack.load(File.read(path)) if File.exist?(path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def dump(load_path, cache)
|
16
|
+
File.open(cache_path(load_path), 'wb+') { |f| f.write(MessagePack.dump(cache)) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def cache_path(load_path)
|
20
|
+
hash = Digest::MD5.hexdigest((load_path + [RUBY_VERSION, Bootscale::VERSION, MessagePack::VERSION]).join('|'))
|
21
|
+
File.join(@directory, "bootscale-#{hash}.msgpack")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/bootscale/setup.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Kernel
|
2
2
|
def require_with_cache(path)
|
3
|
-
require_without_cache(Bootscale[path])
|
3
|
+
require_without_cache(Bootscale[path] || path)
|
4
4
|
end
|
5
5
|
|
6
6
|
alias_method :require_without_cache, :require
|
@@ -9,7 +9,7 @@ end
|
|
9
9
|
|
10
10
|
class << Kernel
|
11
11
|
def require_with_cache(path)
|
12
|
-
require_without_cache(Bootscale[path])
|
12
|
+
require_without_cache(Bootscale[path] || path)
|
13
13
|
end
|
14
14
|
|
15
15
|
alias_method :require_without_cache, :require
|
@@ -18,7 +18,7 @@ end
|
|
18
18
|
|
19
19
|
class Module
|
20
20
|
def autoload_with_cache(const, path)
|
21
|
-
autoload_without_cache(const, Bootscale[path])
|
21
|
+
autoload_without_cache(const, Bootscale[path] || path)
|
22
22
|
end
|
23
23
|
|
24
24
|
alias_method :autoload_without_cache, :autoload
|
data/lib/bootscale/version.rb
CHANGED
data/lib/bootscale.rb
CHANGED
@@ -1,21 +1,60 @@
|
|
1
1
|
require_relative 'bootscale/version'
|
2
|
-
require_relative 'bootscale/entry'
|
3
|
-
require_relative 'bootscale/cache'
|
4
2
|
|
5
3
|
module Bootscale
|
4
|
+
DOT_SO = '.so'.freeze
|
5
|
+
DOT_RB = '.rb'.freeze
|
6
|
+
|
6
7
|
class << self
|
7
8
|
def [](path)
|
8
|
-
|
9
|
+
path = path.to_s
|
10
|
+
if path.end_with?(DOT_RB) || path.end_with?(DOT_SO)
|
11
|
+
cache[path]
|
12
|
+
else
|
13
|
+
cache["#{path}#{DOT_RB}"] || cache["#{path}#{DOT_SO}"]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup(options = {})
|
18
|
+
self.cache_directory = options[:cache_directory]
|
19
|
+
require_relative 'bootscale/setup'
|
20
|
+
regenerate
|
9
21
|
end
|
10
22
|
|
11
23
|
def regenerate
|
12
|
-
cache.
|
24
|
+
@cache = load_cache || save_cache(cache_builder.generate($LOAD_PATH))
|
13
25
|
end
|
14
26
|
|
15
27
|
def cache
|
16
|
-
@cache ||=
|
28
|
+
@cache ||= {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def cache_builder
|
32
|
+
@cache_builder ||= CacheBuilder.new
|
33
|
+
end
|
34
|
+
|
35
|
+
def load_cache
|
36
|
+
return unless storage
|
37
|
+
storage.load($LOAD_PATH)
|
38
|
+
end
|
39
|
+
|
40
|
+
def save_cache(cache)
|
41
|
+
return cache unless storage
|
42
|
+
storage.dump($LOAD_PATH, cache)
|
43
|
+
cache
|
44
|
+
end
|
45
|
+
|
46
|
+
attr_accessor :storage
|
47
|
+
|
48
|
+
def cache_directory=(directory)
|
49
|
+
if directory
|
50
|
+
require_relative 'bootscale/file_storage'
|
51
|
+
self.storage = FileStorage.new(directory)
|
52
|
+
else
|
53
|
+
self.storage = nil
|
54
|
+
end
|
17
55
|
end
|
18
56
|
end
|
19
57
|
end
|
20
58
|
|
21
|
-
require_relative 'bootscale/
|
59
|
+
require_relative 'bootscale/entry'
|
60
|
+
require_relative 'bootscale/cache_builder'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootscale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Boussier
|
@@ -9,7 +9,21 @@ autorequire:
|
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-08-23 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: msgpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.6.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.6.2
|
13
27
|
description: Inspired by Aaron Patterson's talk on the subject
|
14
28
|
email:
|
15
29
|
- jean.boussier@gmail.com
|
@@ -26,8 +40,9 @@ files:
|
|
26
40
|
- bin/setup
|
27
41
|
- bootscale.gemspec
|
28
42
|
- lib/bootscale.rb
|
29
|
-
- lib/bootscale/
|
43
|
+
- lib/bootscale/cache_builder.rb
|
30
44
|
- lib/bootscale/entry.rb
|
45
|
+
- lib/bootscale/file_storage.rb
|
31
46
|
- lib/bootscale/setup.rb
|
32
47
|
- lib/bootscale/version.rb
|
33
48
|
homepage: https://github.com/byroot/bootscale
|
data/lib/bootscale/cache.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'benchmark'
|
2
|
-
|
3
|
-
module Bootscale
|
4
|
-
class Cache
|
5
|
-
attr_reader :entries
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@entries = {}
|
9
|
-
regenerate
|
10
|
-
end
|
11
|
-
|
12
|
-
def [](path)
|
13
|
-
if path.end_with?(DOT_RB) || path.end_with?(DOT_SO)
|
14
|
-
@cache[path]
|
15
|
-
else
|
16
|
-
@cache["#{path}#{DOT_RB}"] || @cache["#{path}#{DOT_SO}"]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def regenerate
|
21
|
-
ordered_entries = $LOAD_PATH.map { |path| entries.fetch(path) { entries[path] = Entry.new(path) } }
|
22
|
-
@cache = Hash[ordered_entries.reverse.flat_map(&:features)]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|