modulation 0.29 → 0.31

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 933737f36bc12f47d347cb770b7f8d4464cd993b26da4d8d309be64c53dc551a
4
- data.tar.gz: 5f385daa43a1ce9312243804be00fc2ddb1a1e728d37d7807d806eae08197ab7
3
+ metadata.gz: a2fdd479aff209b4cf494c13fc4f7bce1ebc64c058ac6860c2dec80928b46b3b
4
+ data.tar.gz: 3ffce99915f23b4d1444e50c2c216e4b695f00ffdc5c5d9ff6960beb03f8fb9e
5
5
  SHA512:
6
- metadata.gz: 8c411047feeb3ca76646b62db47434ff135d8e6645cfaf3b11a5994a65630e2ac13be18a96999410078d05dc68c3a70b108206a7cc8e9afea695d50cbd62851e
7
- data.tar.gz: 5aa45a4ba33c41b0f25c73c70e247952b9943783823f47920296d0583fbbc2a357ecb82beac948fe7656eae7829f9c9c1d7e635b3a8e61d327be759b59410e57
6
+ metadata.gz: 10e1497aa425b14ebabad8247f7898d45f67a255c0b88854c4eeacddaa5ffa36530425d51292f43f478e9043dc15e472a06930b9f9f9d4258e9d9651990eda6e
7
+ data.tar.gz: d84f11b4c5b206e30462a75307d6399492781cf5009426103e176c48aad65222c6f938468da1453755487559ae08848dc7fd641378d2167fc88f050da0d51977
@@ -1,3 +1,13 @@
1
+ 0.31 2019-08-28
2
+ ---------------
3
+
4
+ * Fix error handling when default_export symbol is not found
5
+
6
+ 0.30 2019-08-24
7
+ ---------------
8
+
9
+ * Add symbol_keys option to import_map
10
+
1
11
  0.29 2019-08-23
2
12
  ---------------
3
13
 
@@ -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(1..1).first)
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(1..1).first)
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, caller_location = caller(1..1).first)
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 = yield name, mod if block_given?
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, caller_location = caller(1..1).first)
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(1..1).first)
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(1..1).first)
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 =
@@ -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
@@ -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(1..1).first)
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(1..1).first)
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, caller_location = caller(1..1).first, &block)
27
- Modulation.import_map(path, caller_location, &block)
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, caller_location = caller(1..1).first, &block)
31
- Modulation.auto_import_map(path, caller_location, &block)
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(1..1).first)
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(1..1).first)
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(1..1).first)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Modulation
4
- VERSION = '0.29'
4
+ VERSION = '0.31'
5
5
  end
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.29'
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-23 00:00:00.000000000 Z
11
+ date: 2019-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest