Skip to content

Commit

Permalink
Implement Kangaru.eager_load
Browse files Browse the repository at this point in the history
  • Loading branch information
apexatoll committed Oct 26, 2023
1 parent 35d50a2 commit 444ec16
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/kangaru.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ module Kangaru

class << self
attr_accessor :application

def eager_load(namespace)
@loader.eager_load_namespace(namespace)
end
end
end
2 changes: 2 additions & 0 deletions sig/kangaru.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module Kangaru
@loader: Zeitwerk::Loader

attr_accessor application: Application

def eager_load: (Module) -> void
end

# Included in target applications that extend Kangaru::Initialiser.
Expand Down
5 changes: 5 additions & 0 deletions sig/zeitwerk/loader.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Zeitwerk
class Loader
def eager_load_namespace: (Module) -> void
end
end
19 changes: 19 additions & 0 deletions spec/kangaru_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,23 @@
expect(loader.dirs).to include(lib_directory)
end
end

describe ".eager_load" do
subject(:eager_load) { described_class.eager_load(namespace) }

let(:namespace) { Module.new }

let(:loader) { described_class.instance_variable_get(:@loader) }

before { allow(loader).to receive(:eager_load_namespace) }

it "delegates to the zeitwerk loader" do
eager_load

expect(loader)
.to have_received(:eager_load_namespace)
.with(namespace)
.once
end
end
end

0 comments on commit 444ec16

Please sign in to comment.