modulation 0.29 → 0.31
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/modulation/core.rb +13 -8
- data/lib/modulation/default_export.rb +2 -12
- data/lib/modulation/exports.rb +10 -0
- data/lib/modulation/ext.rb +13 -9
- data/lib/modulation/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2fdd479aff209b4cf494c13fc4f7bce1ebc64c058ac6860c2dec80928b46b3b
|
4
|
+
data.tar.gz: 3ffce99915f23b4d1444e50c2c216e4b695f00ffdc5c5d9ff6960beb03f8fb9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10e1497aa425b14ebabad8247f7898d45f67a255c0b88854c4eeacddaa5ffa36530425d51292f43f478e9043dc15e472a06930b9f9f9d4258e9d9651990eda6e
|
7
|
+
data.tar.gz: d84f11b4c5b206e30462a75307d6399492781cf5009426103e176c48aad65222c6f938468da1453755487559ae08848dc7fd641378d2167fc88f050da0d51977
|
data/CHANGELOG.md
CHANGED
data/lib/modulation/core.rb
CHANGED
@@ -7,6 +7,8 @@ module Modulation
|
|
7
7
|
require_relative './module_mixin'
|
8
8
|
|
9
9
|
class << self
|
10
|
+
CALLER_RANGE = (1..1).freeze
|
11
|
+
|
10
12
|
# @return [Hash] hash of loaded modules, mapping absolute paths to modules
|
11
13
|
attr_reader :loaded_modules
|
12
14
|
|
@@ -31,7 +33,7 @@ module Modulation
|
|
31
33
|
# @param path [String] unqualified file name
|
32
34
|
# @param caller_location [String] caller location
|
33
35
|
# @return [Module] loaded module object
|
34
|
-
def import(path, caller_location = caller(
|
36
|
+
def import(path, caller_location = caller(CALLER_RANGE).first)
|
35
37
|
abs_path = Paths.process(path, caller_location)
|
36
38
|
|
37
39
|
case abs_path
|
@@ -48,7 +50,7 @@ module Modulation
|
|
48
50
|
# @ param path [String] relative directory path
|
49
51
|
# @param caller_location [String] caller location
|
50
52
|
# @return [Array] array of module objects
|
51
|
-
def import_all(path, caller_location = caller(
|
53
|
+
def import_all(path, caller_location = caller(CALLER_RANGE).first)
|
52
54
|
abs_path = Paths.absolute_dir_path(path, caller_location)
|
53
55
|
Dir["#{abs_path}/**/*.rb"].map do |fn|
|
54
56
|
@loaded_modules[fn] || create_module_from_file(fn)
|
@@ -58,19 +60,22 @@ module Modulation
|
|
58
60
|
# Imports all source files in given directory, returning a hash mapping
|
59
61
|
# filenames to modules
|
60
62
|
# @ param path [String] relative directory path
|
63
|
+
# @ param options [Hash] options
|
61
64
|
# @param caller_location [String] caller location
|
62
65
|
# @return [Hash] hash mapping filenames to modules
|
63
|
-
def import_map(path,
|
66
|
+
def import_map(path, options = {},
|
67
|
+
caller_location = caller(CALLER_RANGE).first)
|
64
68
|
abs_path = Paths.absolute_dir_path(path, caller_location)
|
69
|
+
use_symbols = options[:symbol_keys]
|
65
70
|
Dir["#{abs_path}/**/*.rb"].each_with_object({}) do |fn, h|
|
66
71
|
mod = @loaded_modules[fn] || create_module_from_file(fn)
|
67
72
|
name = File.basename(fn) =~ /^(.+)\.rb$/ && Regexp.last_match(1)
|
68
|
-
name
|
69
|
-
h[name] = mod
|
73
|
+
h[use_symbols ? name.to_sym : name] = mod
|
70
74
|
end
|
71
75
|
end
|
72
76
|
|
73
|
-
def auto_import_map(path,
|
77
|
+
def auto_import_map(path, options = {},
|
78
|
+
caller_location = caller(CALLER_RANGE).first)
|
74
79
|
abs_path = Paths.absolute_dir_path(path, caller_location)
|
75
80
|
Hash.new do |h, k|
|
76
81
|
fn = Paths.check_path(File.join(abs_path, k.to_s))
|
@@ -126,7 +131,7 @@ module Modulation
|
|
126
131
|
# @param mod [Module] module
|
127
132
|
# @param caller_location [String] caller location
|
128
133
|
# @return [void]
|
129
|
-
def mock(path, mod, caller_location = caller(
|
134
|
+
def mock(path, mod, caller_location = caller(CALLER_RANGE).first)
|
130
135
|
path = Paths.absolute_path(path, caller_location)
|
131
136
|
old_module = @loaded_modules[path]
|
132
137
|
@loaded_modules[path] = mod
|
@@ -136,7 +141,7 @@ module Modulation
|
|
136
141
|
end
|
137
142
|
|
138
143
|
def add_tags(tags)
|
139
|
-
Paths.add_tags(tags, caller(
|
144
|
+
Paths.add_tags(tags, caller(CALLER_RANGE).first)
|
140
145
|
end
|
141
146
|
end
|
142
147
|
end
|
@@ -24,7 +24,7 @@ module Modulation
|
|
24
24
|
|
25
25
|
def get_module_constant(mod, value)
|
26
26
|
unless mod.singleton_class.constants(true).include?(value)
|
27
|
-
raise_exported_symbol_not_found_error(value, mod, :const)
|
27
|
+
Exports.raise_exported_symbol_not_found_error(value, mod, :const)
|
28
28
|
end
|
29
29
|
|
30
30
|
mod.singleton_class.const_get(value)
|
@@ -32,22 +32,12 @@ module Modulation
|
|
32
32
|
|
33
33
|
def get_module_method(mod, value)
|
34
34
|
unless mod.singleton_class.instance_methods(true).include?(value)
|
35
|
-
raise_exported_symbol_not_found_error(value, mod, :method)
|
35
|
+
Exports.raise_exported_symbol_not_found_error(value, mod, :method)
|
36
36
|
end
|
37
37
|
|
38
38
|
proc { |*args, &block| mod.send(value, *args, &block) }
|
39
39
|
end
|
40
40
|
|
41
|
-
NOT_FOUND_MSG = '%s %s not found in module'
|
42
|
-
|
43
|
-
def raise_exported_symbol_not_found_error(sym, mod, kind)
|
44
|
-
msg = format(
|
45
|
-
NOT_FOUND_MSG, kind == :method ? 'Method' : 'Constant', sym
|
46
|
-
)
|
47
|
-
error = NameError.new(msg)
|
48
|
-
Modulation.raise_error(error, mod.__export_backtrace)
|
49
|
-
end
|
50
|
-
|
51
41
|
# Error message to be displayed when trying to set a singleton value as
|
52
42
|
# default export
|
53
43
|
DEFAULT_VALUE_ERROR_MSG =
|
data/lib/modulation/exports.rb
CHANGED
@@ -58,6 +58,16 @@ module Modulation
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
61
|
+
|
62
|
+
NOT_FOUND_MSG = '%s %s not found in module'
|
63
|
+
|
64
|
+
def raise_exported_symbol_not_found_error(sym, mod, kind)
|
65
|
+
msg = format(
|
66
|
+
NOT_FOUND_MSG, kind == :method ? 'Method' : 'Constant', sym
|
67
|
+
)
|
68
|
+
error = NameError.new(msg)
|
69
|
+
Modulation.raise_error(error, mod.__export_backtrace)
|
70
|
+
end
|
61
71
|
end
|
62
72
|
end
|
63
73
|
end
|
data/lib/modulation/ext.rb
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
# Kernel extensions
|
4
4
|
module Kernel
|
5
|
+
CALLER_RANGE = (1..1).freeze
|
6
|
+
|
5
7
|
# Imports a module
|
6
8
|
# @param path [String] module file name
|
7
9
|
# @param caller_location [String] caller location
|
8
10
|
# @return [Module] module object
|
9
|
-
def import(path, caller_location = caller(
|
11
|
+
def import(path, caller_location = caller(CALLER_RANGE).first)
|
10
12
|
Modulation.import(path, caller_location)
|
11
13
|
end
|
12
14
|
|
@@ -14,7 +16,7 @@ module Kernel
|
|
14
16
|
# @param path [String] directory path
|
15
17
|
# @param caller_location [String] caller location
|
16
18
|
# @return [Array] array of module objects
|
17
|
-
def import_all(path, caller_location = caller(
|
19
|
+
def import_all(path, caller_location = caller(CALLER_RANGE).first)
|
18
20
|
Modulation.import_all(path, caller_location)
|
19
21
|
end
|
20
22
|
|
@@ -23,12 +25,14 @@ module Kernel
|
|
23
25
|
# @param path [String] directory path
|
24
26
|
# @param caller_location [String] caller location
|
25
27
|
# @return [Hash] hash mapping filenames to module objects
|
26
|
-
def import_map(path,
|
27
|
-
|
28
|
+
def import_map(path, options = {},
|
29
|
+
caller_location = caller(CALLER_RANGE).first)
|
30
|
+
Modulation.import_map(path, options, caller_location)
|
28
31
|
end
|
29
32
|
|
30
|
-
def auto_import_map(path,
|
31
|
-
|
33
|
+
def auto_import_map(path, options = {},
|
34
|
+
caller_location = caller(CALLER_RANGE).first)
|
35
|
+
Modulation.auto_import_map(path, options, caller_location)
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
@@ -38,7 +42,7 @@ class Module
|
|
38
42
|
# @param sym [Symbol, Hash] constant name or hash mapping names to paths
|
39
43
|
# @param path [String] path if sym is Symbol
|
40
44
|
# @return [void]
|
41
|
-
def auto_import(sym, path = nil, caller_location = caller(
|
45
|
+
def auto_import(sym, path = nil, caller_location = caller(CALLER_RANGE).first)
|
42
46
|
setup_auto_import_registry unless @__auto_import_registry
|
43
47
|
if path
|
44
48
|
@__auto_import_registry[sym] = [path, caller_location]
|
@@ -59,7 +63,7 @@ class Module
|
|
59
63
|
# @param path [String] module filename
|
60
64
|
# @return [void]
|
61
65
|
def extend_from(path)
|
62
|
-
mod = import(path, caller(
|
66
|
+
mod = import(path, caller(CALLER_RANGE).first)
|
63
67
|
Modulation::Builder.add_module_methods(mod, self.class)
|
64
68
|
Modulation::Builder.add_module_constants(mod, self)
|
65
69
|
end
|
@@ -70,7 +74,7 @@ class Module
|
|
70
74
|
# @param symbols [Array<Symbol>] list of symbols to include
|
71
75
|
# @return [void]
|
72
76
|
def include_from(path, *symbols)
|
73
|
-
mod = import(path, caller(
|
77
|
+
mod = import(path, caller(CALLER_RANGE).first)
|
74
78
|
Modulation::Builder.add_module_methods(mod, self, *symbols)
|
75
79
|
Modulation::Builder.add_module_constants(mod, self, *symbols)
|
76
80
|
end
|
data/lib/modulation/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modulation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.31'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|