modules 1.0.0 → 1.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 +4 -4
- data/bin/modules +1 -1
- data/lib/interop.rb +7 -5
- data/lib/loader.rb +10 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8b3e8df22cfbaf45a2aaca8d2a27f2f1408a962
|
4
|
+
data.tar.gz: 43bb05d97bf467b1723ff1f9afc36da59a373b7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61ae2e1246455ba92b6ea0762b81d8b861eb0337e26a5c2beba6ab321e5c08bf02609d680cdcb0f92d1c5241d318f3ec8dfdb605c8c241f82f841e8bc045cfc9
|
7
|
+
data.tar.gz: 622e7875c5c4733b785508bee20bc6c0d0fedd20f822096b86b6e86b0355999fe0feb8ccca625f4a5d716a853ff31ed9d1b75a83cc5c08df5d1f6e15bbeac9df
|
data/bin/modules
CHANGED
data/lib/interop.rb
CHANGED
@@ -8,7 +8,7 @@ module Interop
|
|
8
8
|
# (Hash) map from module identifier to resolved module
|
9
9
|
@cache = {}
|
10
10
|
|
11
|
-
def self.import(id)
|
11
|
+
def self.import(id, opts={})
|
12
12
|
if @cache.include?(id)
|
13
13
|
DEBUG.call "Cache hit #{id}"
|
14
14
|
return @cache[id]
|
@@ -17,14 +17,16 @@ module Interop
|
|
17
17
|
DEBUG.call "Load #{id}"
|
18
18
|
snapshot = Module.constants
|
19
19
|
require id
|
20
|
-
cleanly_load(Module.constants - snapshot)
|
20
|
+
cleanly_load(Module.constants - snapshot, opts)
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.cleanly_load(targets)
|
23
|
+
def self.cleanly_load(targets, opts)
|
24
24
|
DEBUG.call "Package definitions #{targets}"
|
25
25
|
result = wrap_constants(targets)
|
26
|
-
|
27
|
-
|
26
|
+
if !opts[:save_the_environment]
|
27
|
+
result.each_pair do |key, value|
|
28
|
+
Object.send(:remove_const, key.to_sym) unless key.include?('::')
|
29
|
+
end
|
28
30
|
end
|
29
31
|
|
30
32
|
result
|
data/lib/loader.rb
CHANGED
@@ -13,6 +13,9 @@ module Loader
|
|
13
13
|
# (String) path to the file currently being loaded
|
14
14
|
@path = nil
|
15
15
|
|
16
|
+
# (Boolean) whether to purge constants added to global namespace on interop load
|
17
|
+
@save_the_environment = false
|
18
|
+
|
16
19
|
def self.export(value)
|
17
20
|
if @cache.include?(@path) && value.class == Hash
|
18
21
|
# Special handling to enable multiple exports
|
@@ -24,7 +27,7 @@ module Loader
|
|
24
27
|
|
25
28
|
def self.import(id, type=nil)
|
26
29
|
if type == 'interop'
|
27
|
-
return Interop.import(id)
|
30
|
+
return Interop.import(id, save_the_environment: @save_the_environment)
|
28
31
|
end
|
29
32
|
|
30
33
|
prev = @path
|
@@ -54,7 +57,7 @@ module Loader
|
|
54
57
|
result = @cache[@path]
|
55
58
|
else
|
56
59
|
# Failover to external load.
|
57
|
-
result = Interop.import(id)
|
60
|
+
result = Interop.import(id, save_the_environment: @save_the_environment)
|
58
61
|
end
|
59
62
|
|
60
63
|
@path = prev
|
@@ -77,8 +80,11 @@ module Loader
|
|
77
80
|
end
|
78
81
|
|
79
82
|
def self.config(opts)
|
80
|
-
|
81
|
-
|
83
|
+
[
|
84
|
+
:basepath,
|
85
|
+
:save_the_environment,
|
86
|
+
].each do |opt|
|
87
|
+
Loader.instance_variable_set("@#{opt}", opts[opt]) if opts.include?(opt)
|
82
88
|
end
|
83
89
|
end
|
84
90
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modules
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gareth (Ari) Aye
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Ruby module loader inspired by the semantics of js modules
|
14
14
|
email: gareth@alumni.middlebury.edu
|