File: inceptions.rb

package info (click to toggle)
ruby-zeitwerk 2.7.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 732 kB
  • sloc: ruby: 6,240; makefile: 4
file content (31 lines) | stat: -rw-r--r-- 742 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Zeitwerk::Registry
  # Loaders know their own inceptions, but there is a use case in which we need
  # to know if a given cpath is an inception globally. This is what this
  # registry is for.
  class Inceptions # :nodoc:
    #: () -> void
    def initialize
      @inceptions = Zeitwerk::Cref::Map.new #: Zeitwerk::Cref::Map[String]
    end

    #: (Zeitwerk::Cref, String) -> void
    def register(cref, abspath)
      @inceptions[cref] = abspath
    end

    #: (Zeitwerk::Cref) -> String?
    def registered?(cref)
      @inceptions[cref]
    end

    #: (Zeitwerk::Cref) -> void
    def unregister(cref)
      @inceptions.delete(cref)
    end

    #: () -> void
    def clear # for tests
      @inceptions.clear
    end
  end
end