modules 1.1.1 → 1.1.2
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 +5 -4
- data/lib/modules/callsite.rb +9 -0
- data/lib/modules/loader.rb +19 -25
- data/lib/modules/modules.rb +1 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff9bd70ed4bbc3c8462b2a444ee10801aa0794f6
|
4
|
+
data.tar.gz: 5307157838a65581d6599e0e71da499488cd4a79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cad0b747b3b3c7137b87c2c16d047ca7742030f379bfdd513a3ab6b1661e1b3fae7b5266ed151f60de20cb92a2bc0bf4a01302686d47b084fafc381f1bbc698d
|
7
|
+
data.tar.gz: f98b425cd789c94e867eb9d6d7ebfd3aff4652f032338b33445fcc058d20c0a7d7d8d41e9bff373c634bb728c39969e4a51b33dd19e8d93066f2d3df030454e8
|
data/bin/modules
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'optparse'
|
4
4
|
|
5
|
-
require_relative '../lib/
|
6
|
-
require_relative '../lib/modules'
|
5
|
+
require_relative '../lib/modules/modules'
|
7
6
|
|
8
7
|
def main
|
9
8
|
options = {}
|
@@ -16,7 +15,7 @@ def main
|
|
16
15
|
end
|
17
16
|
|
18
17
|
opts.on('-v', '--version') do
|
19
|
-
puts '1.1.
|
18
|
+
puts '1.1.2'
|
20
19
|
exit
|
21
20
|
end
|
22
21
|
end
|
@@ -25,4 +24,6 @@ def main
|
|
25
24
|
Modules.main(ARGV[0], ARGV[1..-1], options)
|
26
25
|
end
|
27
26
|
|
28
|
-
|
27
|
+
if __FILE__ == $0
|
28
|
+
main
|
29
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Callsite
|
2
|
+
# Prefer caller_locations since it's faster, but failover to caller
|
3
|
+
# since caller_locations was only introduced in v2.0.0.
|
4
|
+
def self.resolve(idx=1)
|
5
|
+
defined?(caller_locations) ?
|
6
|
+
caller_locations[idx + 1].absolute_path :
|
7
|
+
caller[idx + 1].split(':').first
|
8
|
+
end
|
9
|
+
end
|
data/lib/modules/loader.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require_relative './callsite'
|
1
2
|
require_relative './debug'
|
2
3
|
require_relative './interop'
|
3
4
|
|
@@ -10,18 +11,19 @@ module Loader
|
|
10
11
|
# (Hash) map from module identifier to resolved module
|
11
12
|
@cache = {}
|
12
13
|
|
13
|
-
# (
|
14
|
-
@
|
14
|
+
# (Boolean) Whether or not import has been called at least once.
|
15
|
+
@import_called = false
|
15
16
|
|
16
17
|
# (Boolean) whether to purge constants added to global namespace on interop load
|
17
18
|
@save_the_environment = false
|
18
19
|
|
19
20
|
def self.export(value)
|
20
|
-
|
21
|
+
callsite = Callsite.resolve
|
22
|
+
if @cache.include?(callsite) && value.class == Hash
|
21
23
|
# Special handling to enable multiple exports
|
22
|
-
@cache[
|
24
|
+
@cache[callsite] = @cache[callsite].merge(value)
|
23
25
|
else
|
24
|
-
@cache[
|
26
|
+
@cache[callsite] = value
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
@@ -30,38 +32,30 @@ module Loader
|
|
30
32
|
return Interop.import(id, save_the_environment: @save_the_environment)
|
31
33
|
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
container = File.dirname(@path)
|
39
|
-
raw = File.join(container, id)
|
40
|
-
end
|
41
|
-
|
42
|
-
@path = File.expand_path(raw)
|
43
|
-
filepath = @path.end_with?('.rb') ? @path : "#{@path}.rb"
|
35
|
+
callsite = Callsite.resolve
|
36
|
+
parent = @import_called ? File.dirname(callsite) : @basepath
|
37
|
+
raw = File.join(parent, id)
|
38
|
+
path = File.expand_path(raw)
|
39
|
+
filepath = path.end_with?('.rb') ? path : "#{path}.rb"
|
44
40
|
exists = File.exist?(filepath)
|
41
|
+
|
45
42
|
if type == 'internal' && !exists
|
46
|
-
raise "Could not resolve local module at #{
|
43
|
+
raise "Could not resolve local module at #{path}"
|
47
44
|
end
|
48
45
|
|
49
46
|
if exists
|
50
47
|
# Prefer loading local module since we found it.
|
51
48
|
begin
|
52
|
-
Kernel.load(filepath, true) unless @cache.include?(
|
49
|
+
Kernel.load(filepath, true) unless @cache.include?(filepath)
|
53
50
|
rescue => e
|
54
|
-
raise LoadError, "Could not load #{filepath} from #{
|
51
|
+
raise LoadError, "Could not load #{filepath} from #{parent}: #{e}"
|
55
52
|
end
|
56
53
|
|
57
|
-
|
58
|
-
else
|
59
|
-
# Failover to external load.
|
60
|
-
result = Interop.import(id, save_the_environment: @save_the_environment)
|
54
|
+
return @cache[filepath]
|
61
55
|
end
|
62
56
|
|
63
|
-
|
64
|
-
|
57
|
+
# Failover to external load.
|
58
|
+
return Interop.import(id, save_the_environment: @save_the_environment)
|
65
59
|
end
|
66
60
|
|
67
61
|
module Api
|
data/lib/modules/modules.rb
CHANGED
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.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gareth (Ari) Aye
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-03 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
|
@@ -19,6 +19,7 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- bin/modules
|
21
21
|
- lib/modules.rb
|
22
|
+
- lib/modules/callsite.rb
|
22
23
|
- lib/modules/debug.rb
|
23
24
|
- lib/modules/interop.rb
|
24
25
|
- lib/modules/loader.rb
|
@@ -27,7 +28,7 @@ homepage: https://github.com/lambdabaa/modules
|
|
27
28
|
licenses:
|
28
29
|
- MIT
|
29
30
|
metadata: {}
|
30
|
-
post_install_message:
|
31
|
+
post_install_message:
|
31
32
|
rdoc_options: []
|
32
33
|
require_paths:
|
33
34
|
- lib
|
@@ -42,9 +43,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
43
|
- !ruby/object:Gem::Version
|
43
44
|
version: '0'
|
44
45
|
requirements: []
|
45
|
-
rubyforge_project:
|
46
|
+
rubyforge_project:
|
46
47
|
rubygems_version: 2.4.8
|
47
|
-
signing_key:
|
48
|
+
signing_key:
|
48
49
|
specification_version: 4
|
49
50
|
summary: Port of js module loader to ruby
|
50
51
|
test_files: []
|