opal-zeitwerk 0.0.4 → 0.1.0

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: c08d0237fce54d7885badfdda17e4c5b287627af98e41acb14f867ecc7b77631
4
- data.tar.gz: 365a26b762cc3db8c2577bf093c87010a60315358f69572169a855f054bf7e71
3
+ metadata.gz: 926d4439591306fd785d55b4f69b3b60212c3db911255d9cfad96286f22c373b
4
+ data.tar.gz: f541fcfaac3eb639f070c11a8909835a5401669ce69e41c723b9a583c312e3ab
5
5
  SHA512:
6
- metadata.gz: c1cddfe4dfbfed3c28f8081e44d71cf3c4e6682d7d09ed3ca2f456251eb89b60c490fdaf192d9346c3c263655a1f2821a90791e42987c6693faebe151d503130
7
- data.tar.gz: e89409525a50a0693ee2f8578020b618c44e2b33fe9561c02b1925c54b1c6c8e61505f80e03209b1244f5bd20c36b6049f514817139eaaa94f9238c5851aef99
6
+ metadata.gz: ccac14d70164bbfd729f56c3ef9eaf1cb50716d83b218845da396e83db85b9866f5520290e5b8d6bda32c2463c27d05e67ba11748630b1f817f4cbc6c5cf7224
7
+ data.tar.gz: df5c01643cd645039b5b7b51206dda6461b9c7e6312310c1538b86d5c7ed841b9738cb29d710a75abcd7f7151173459683a30b21ca8b9da8cd32d56be277d6d4
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Opal
3
3
  module Zeitwerk
4
- VERSION = "0.0.4"
4
+ VERSION = "0.1.0"
5
5
  end
6
6
  end
@@ -51,12 +51,12 @@ module Zeitwerk
51
51
  # If the class is a singleton class, we won't do anything with it so we
52
52
  # can bail out immediately. This is several orders of magnitude faster
53
53
  # than accessing its name.
54
- return if event.self.singleton_class?
54
+ return if event.singleton_class?
55
55
 
56
56
  # Note that it makes sense to compute the hash code unconditionally,
57
57
  # because the trace point is disabled if cpaths is empty.
58
- if loader = cpaths.delete(real_mod_name(event.self))
59
- loader.on_namespace_loaded(event.self)
58
+ if loader = cpaths.delete(real_mod_name(event))
59
+ loader.on_namespace_loaded(event)
60
60
  disable_tracer_if_unneeded
61
61
  end
62
62
  end
@@ -153,7 +153,7 @@ module Zeitwerk
153
153
  #
154
154
  # @return [<String>]
155
155
  def dirs
156
- root_dirs.keys.freeze
156
+ root_dirs.keys
157
157
  end
158
158
 
159
159
  # Pushes `path` to the list of root directories.
@@ -288,6 +288,7 @@ module Zeitwerk
288
288
  ExplicitNamespace.unregister(self)
289
289
 
290
290
  @setup = false
291
+ @eager_loaded = false
291
292
  end
292
293
 
293
294
  # Unloads all loaded code, and calls setup again so that the loader is able
@@ -367,7 +368,7 @@ module Zeitwerk
367
368
  #
368
369
  # @return [<String>]
369
370
  def unloadable_cpaths
370
- to_unload.keys.freeze
371
+ to_unload.keys
371
372
  end
372
373
 
373
374
  # @private
@@ -401,7 +402,7 @@ module Zeitwerk
401
402
  #
402
403
  # @return [<String>]
403
404
  def all_dirs
404
- Registry.loaders.flat_map(&:dirs).freeze
405
+ Registry.loaders.flat_map(&:dirs)
405
406
  end
406
407
  end
407
408
 
@@ -429,8 +430,7 @@ module Zeitwerk
429
430
  end
430
431
  rescue ::NameError => error
431
432
  path_type = ruby?(abspath) ? "file" : "directory"
432
-
433
- raise NameError, <<~MESSAGE
433
+ message = <<~MESSAGE
434
434
  #{error.message} inferred by #{inflector.class} from #{path_type}
435
435
 
436
436
  #{abspath}
@@ -442,6 +442,7 @@ module Zeitwerk
442
442
  * Rename the #{path_type} to comply with the naming conventions.
443
443
  * Modify the inflector to handle this case.
444
444
  MESSAGE
445
+ raise NameError.new(message, error.name)
445
446
  end
446
447
  end
447
448
  end
@@ -499,6 +500,17 @@ module Zeitwerk
499
500
  # "file #{file} is ignored because #{cpath(parent, cname)} is already defined"
500
501
  else
501
502
  set_autoload(parent, cname, file)
503
+ if autoload_path = autoload_for?(parent, cname)
504
+ if dir?(autoload_path)
505
+ promote_namespace_from_implicit_to_explicit(
506
+ dir: autoload_path,
507
+ file: file,
508
+ parent: parent,
509
+ cname: cname
510
+ )
511
+ (lazy_subdirs[cpath(parent, cname)] ||= []) << autoload_path
512
+ end
513
+ end
502
514
  end
503
515
  end
504
516
 
@@ -561,14 +573,8 @@ module Zeitwerk
561
573
  # @param parent [Module]
562
574
  # @param cname [Symbol]
563
575
  # @return [String, nil]
564
- if method(:autoload?).arity == 1
565
- def strict_autoload_path(parent, cname)
566
- parent.autoload?(cname) if cdef?(parent, cname)
567
- end
568
- else
569
- def strict_autoload_path(parent, cname)
570
- parent.autoload?(cname, false)
571
- end
576
+ def strict_autoload_path(parent, cname)
577
+ parent.autoload?(cname, false)
572
578
  end
573
579
 
574
580
  # This method is called this way because I prefer `preload` to be the method
@@ -629,7 +635,7 @@ module Zeitwerk
629
635
  dir_first_char = dir[0]
630
636
  path_start = dir.size + 1
631
637
  path_parts = `[]`
632
- basename = `''`
638
+ basename = ''
633
639
  @module_paths.each do |abspath|
634
640
  %x{
635
641
  if (abspath[0] === dir_first_char) {
@@ -13,7 +13,7 @@ module Zeitwerk::Loader::Callbacks
13
13
 
14
14
  # "constant #{cpath(*cref)} loaded from file #{file}" if cdef?(*cref)
15
15
  if !cdef?(*cref)
16
- raise Zeitwerk::NameError, "expected file #{file} to define constant #{cpath(*cref)}, but didn't"
16
+ raise Zeitwerk::NameError.new("expected file #{file} to define constant #{cpath(*cref)}, but didn't", cref.last)
17
17
  end
18
18
  end
19
19
 
@@ -25,11 +25,8 @@ module Zeitwerk::Loader::Callbacks
25
25
  # @return [void]
26
26
  def on_dir_autoloaded(dir)
27
27
  if cref = autoloads.delete(dir)
28
- autovivified_module = if vivify_mod_dir && dir.start_with?(vivify_mod_dir)
29
- cref[0].const_set(cref[1], vivify_mod_class.new)
30
- else
31
- cref[0].const_set(cref[1], Module.new)
32
- end
28
+ autovivified_module = cref[0].const_set(cref[1], Module.new)
29
+
33
30
  # "module #{autovivified_module.name} autovivified from directory #{dir}"
34
31
 
35
32
  to_unload[autovivified_module.name] = [dir, cref] if reloading_enabled?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-zeitwerk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-19 00:00:00.000000000 Z
11
+ date: 2019-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -52,7 +52,7 @@ licenses:
52
52
  - MIT
53
53
  metadata:
54
54
  github_repo: ssh://github.com/isomorfeus/gems
55
- post_install_message: "\nopal-zeitwerk 0.0.4:\n \n opal-zeitwerk currently requires
55
+ post_install_message: "\nopal-zeitwerk 0.1.0:\n \n opal-zeitwerk currently requires
56
56
  the es6_modules_1_1 branch of opal, for the Gemfile:\n\n gem 'opal', github: 'janbiedermann/opal',
57
57
  branch: 'es6_modules_1_1'\n\n"
58
58
  rdoc_options: []