modules 0.0.1 → 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 +5 -13
- data/bin/modules +2 -1
- data/lib/modules.rb +4 -100
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MjYzYzQxYTU3NGRkZjllYjU2OGIxMTNkMmQ4ZmNjZmI3NmI1YjUyMg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7699497008a6418461da4427558e32f53b914775
|
4
|
+
data.tar.gz: ac706ced9a11c7b0470aa03ddd92bb24205496c6
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZWRiNzBhNzQxMTdjYjEzYTdkOTJkZGNlZjhkNzFiN2I3ODkxNGM4ZWNiOWZm
|
11
|
-
MGNiZTZkZWUwYThkODExM2FlMGNkNWY3ZjU0MzFmYWFhYjdkOGU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MDEyOGVlM2ZhZmUzNWEyMDY3NGU1ODVhOGNiNzg2ZWE2OTM2MTViNmVmZDVm
|
14
|
-
ZjFiMjQwMzdmMWZiOTA5Y2I0MzY4ZGRhZDRmN2VhZWY5NGM1NGU2YTA2Njcw
|
15
|
-
MTdiYTNlMWQxODA1ZjNjOTJmZjhhN2FjMGVlM2JkNzk5NjRhODU=
|
6
|
+
metadata.gz: 6efb175efebc3ce581ed8eecea657aaedd5ad20be1aa5d35800dac0c73cf08ebdee061238cfc9b6f5210d0c2cf524e38aab1c9806e9da065f10199b75b30336c
|
7
|
+
data.tar.gz: c10b0f98d1e7de2f66df1e1f84b7345a214c9a3d5203a6a360bfba7960e4744352ee3c3d348722a8f2b50ebe71188cadcb92c22f8f6cf4844bf8a1adcb708553
|
data/bin/modules
CHANGED
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
require 'optparse'
|
4
4
|
|
5
|
+
require_relative '../lib/global'
|
5
6
|
require_relative '../lib/modules'
|
6
7
|
|
7
8
|
def main
|
8
9
|
options = {}
|
9
10
|
parser = OptionParser.new do |opts|
|
10
|
-
opts.banner = 'Usage
|
11
|
+
opts.banner = 'Usage: modules run [options]'
|
11
12
|
opts.separator ''
|
12
13
|
opts.on('-d', '--debug', 'Print debug information to stdout') do |debug|
|
13
14
|
options['debug'] = debug
|
data/lib/modules.rb
CHANGED
@@ -1,85 +1,11 @@
|
|
1
|
-
|
2
|
-
# (String) root path for module resolution
|
3
|
-
@basepath = '/'
|
4
|
-
|
5
|
-
# (Hash) map from module identifier to resolved module
|
6
|
-
@cache = {}
|
7
|
-
|
8
|
-
# (String) most recent directory that import was invoked on
|
9
|
-
@dirname = '/'
|
10
|
-
|
11
|
-
# (String) most recent path that import was invoked on
|
12
|
-
@path = '/'
|
13
|
-
|
14
|
-
def self.internal_import(dirname, basename)
|
15
|
-
path = File.join @basepath, dirname, basename
|
16
|
-
if @cache.include? @path
|
17
|
-
puts "Already cached local module #{path}"
|
18
|
-
return @cache[path]
|
19
|
-
end
|
20
|
-
|
21
|
-
puts "Loading local module #{path}"
|
22
|
-
prev_dirname = @dirname
|
23
|
-
prev_path = @path
|
24
|
-
@dirname = dirname
|
25
|
-
@path = path
|
26
|
-
require @path
|
27
|
-
@dirname = prev_dirname
|
28
|
-
@path = prev_path
|
29
|
-
return @cache[path]
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.external_import(name)
|
33
|
-
if @cache.include? name
|
34
|
-
puts "Already cached external module #{name}"
|
35
|
-
return @cache[name]
|
36
|
-
end
|
37
|
-
|
38
|
-
puts "Loading external module #{name}"
|
39
|
-
snapshot = Module.constants
|
40
|
-
require name
|
41
|
-
defined = Module.constants - snapshot
|
42
|
-
p defined
|
43
|
-
plucked = []
|
44
|
-
resolved = {}
|
45
|
-
while defined.length > 0
|
46
|
-
todo = defined.pop
|
47
|
-
plucked.push todo
|
48
|
-
str = todo.to_s
|
49
|
-
const = eval str
|
50
|
-
next if const.nil?
|
51
|
-
resolved[str] = const.class == Module ? Class.new.extend(const) : const
|
52
|
-
if const.respond_to? :constants
|
53
|
-
children = const
|
54
|
-
.constants
|
55
|
-
.map {|child| "#{str}::#{child.to_s}"}
|
56
|
-
.select {|id|
|
57
|
-
parts = id.split '::'
|
58
|
-
groups = parts.group_by {|x| x}
|
59
|
-
groups.values.all? {|group| group.length < 3}
|
60
|
-
}
|
61
|
-
|
62
|
-
defined += children
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
puts "Found #{resolved}"
|
67
|
-
@cache[name] = resolved
|
68
|
-
plucked
|
69
|
-
.select {|item| item.class == Symbol}
|
70
|
-
.each {|item| Object.send(:remove_const, item)}
|
71
|
-
return resolved
|
72
|
-
end
|
1
|
+
require_relative './loader'
|
73
2
|
|
3
|
+
module Modules
|
74
4
|
def self.run(args, opts)
|
75
5
|
file = args[0]
|
76
6
|
abs = "#{Dir.pwd}/#{file}"
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
puts "Set default basepath to #{dirname}"
|
81
|
-
@basepath = dirname
|
82
|
-
internal_import '', basename
|
7
|
+
Loader.set_basepath(File.dirname(abs))
|
8
|
+
Loader.import(File.basename(abs), 'internal')
|
83
9
|
end
|
84
10
|
|
85
11
|
def self.main(cmd, args, opts)
|
@@ -91,25 +17,3 @@ module Modules
|
|
91
17
|
end
|
92
18
|
end
|
93
19
|
end
|
94
|
-
|
95
|
-
class Object
|
96
|
-
def export
|
97
|
-
cache = Modules.instance_variable_get :@cache
|
98
|
-
path = Modules.instance_variable_get :@path
|
99
|
-
cache[path] = yield
|
100
|
-
end
|
101
|
-
|
102
|
-
def import(name)
|
103
|
-
if name[0] == '.'
|
104
|
-
# Treat as local module.
|
105
|
-
dirname = Modules.instance_variable_get :@dirname
|
106
|
-
child_path = File.join dirname, name[1..-1]
|
107
|
-
child_dirname = File.dirname child_path
|
108
|
-
child_basename = File.basename child_path
|
109
|
-
Modules.internal_import child_dirname, child_basename
|
110
|
-
else
|
111
|
-
# Treat as external ruby import.
|
112
|
-
Modules.external_import name
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modules
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
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
11
|
date: 2017-01-15 00:00:00.000000000 Z
|
@@ -23,24 +23,24 @@ homepage: https://github.com/lambdabaa/modules
|
|
23
23
|
licenses:
|
24
24
|
- MIT
|
25
25
|
metadata: {}
|
26
|
-
post_install_message:
|
26
|
+
post_install_message:
|
27
27
|
rdoc_options: []
|
28
28
|
require_paths:
|
29
29
|
- lib
|
30
30
|
required_ruby_version: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '0'
|
35
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- -
|
37
|
+
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
requirements: []
|
41
|
-
rubyforge_project:
|
42
|
-
rubygems_version: 2.
|
43
|
-
signing_key:
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.4.8
|
43
|
+
signing_key:
|
44
44
|
specification_version: 4
|
45
45
|
summary: Port of js module loader to ruby
|
46
46
|
test_files: []
|