Class: Jets::Autoloaders

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/jets/autoloaders.rb,
lib/jets/autoloaders/gem.rb,
lib/jets/autoloaders/inflector.rb

Defined Under Namespace

Modules: Inflector Classes: Gem, GemInflector

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAutoloaders

Returns a new instance of Autoloaders.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jets/autoloaders.rb', line 13

def initialize
  # This `require` delays loading the library on purpose.
  #
  # In Rails 7.0.0, railties/lib/rails.rb loaded Zeitwerk as a side-effect,
  # but a couple of edge cases related to Bundler and Bootsnap showed up.
  # They had to do with order of decoration of `Kernel#require`, something
  # the three of them do.
  #
  # Delaying this `require` up to this point is a convenient trade-off.
  require "zeitwerk"

  @main = Zeitwerk::Loader.new
  @main.tag = "jets.main"
  @main.inflector = Inflector

  @once = Zeitwerk::Loader.new
  @once.tag = "jets.once"
  @once.inflector = Inflector
end

Instance Attribute Details

#mainObject (readonly)

Returns the value of attribute main.



11
12
13
# File 'lib/jets/autoloaders.rb', line 11

def main
  @main
end

#onceObject (readonly)

Returns the value of attribute once.



11
12
13
# File 'lib/jets/autoloaders.rb', line 11

def once
  @once
end

Class Method Details

.for_gemObject



46
47
48
# File 'lib/jets/autoloaders.rb', line 46

def self.for_gem
  Gem.new.autoloader
end

Instance Method Details

#each {|main| ... } ⇒ Object

Yields:



33
34
35
36
# File 'lib/jets/autoloaders.rb', line 33

def each
  yield main
  yield once
end

#log!Object



42
43
44
# File 'lib/jets/autoloaders.rb', line 42

def log!
  each(&:log!)
end

#logger=(logger) ⇒ Object



38
39
40
# File 'lib/jets/autoloaders.rb', line 38

def logger=(logger)
  each { |loader| loader.logger = logger }
end