From af13c380fa6e8248a358869f3248d94dd4848880 Mon Sep 17 00:00:00 2001 From: Chris Welham <71787007+apexatoll@users.noreply.github.com> Date: Thu, 26 Oct 2023 11:16:00 +0100 Subject: [PATCH] Update Initialiser to autoload Initialisers module --- lib/kangaru/initialiser.rb | 1 + lib/kangaru/initialisers.rb | 4 ++++ sig/kangaru/initialisers.rbs | 4 ++++ spec/kangaru/initialiser_spec.rb | 10 ++++++++++ 4 files changed, 19 insertions(+) create mode 100644 lib/kangaru/initialisers.rb create mode 100644 sig/kangaru/initialisers.rbs diff --git a/lib/kangaru/initialiser.rb b/lib/kangaru/initialiser.rb index a1e7072..55aae43 100644 --- a/lib/kangaru/initialiser.rb +++ b/lib/kangaru/initialiser.rb @@ -22,6 +22,7 @@ def self.extended(namespace) source = caller[0].gsub(/:.*$/, "") Kangaru.application = Application.new(source:, namespace:) + Kangaru.eager_load(Initialisers) namespace.extend InjectedMethods end diff --git a/lib/kangaru/initialisers.rb b/lib/kangaru/initialisers.rb new file mode 100644 index 0000000..76e016e --- /dev/null +++ b/lib/kangaru/initialisers.rb @@ -0,0 +1,4 @@ +module Kangaru + module Initialisers + end +end diff --git a/sig/kangaru/initialisers.rbs b/sig/kangaru/initialisers.rbs new file mode 100644 index 0000000..76e016e --- /dev/null +++ b/sig/kangaru/initialisers.rbs @@ -0,0 +1,4 @@ +module Kangaru + module Initialisers + end +end diff --git a/spec/kangaru/initialiser_spec.rb b/spec/kangaru/initialiser_spec.rb index db589a5..a7e0dd1 100644 --- a/spec/kangaru/initialiser_spec.rb +++ b/spec/kangaru/initialiser_spec.rb @@ -5,6 +5,7 @@ stub_const "Namespace", Module.new allow(Kangaru::Application).to receive(:new).and_return(application) + allow(Kangaru).to receive(:eager_load) allow_any_instance_of(Kernel).to receive(:caller).and_return([callsite]) end @@ -40,6 +41,15 @@ .to change { Kangaru.application } .to(application) end + + it "eager loads the Initialisers namespace" do + extended + + expect(Kangaru) + .to have_received(:eager_load) + .with(Kangaru::Initialisers) + .once + end end context "when calling file is not in a gem structure" do