Skip to content

Commit

Permalink
Update Initialiser to set run! method on target gem
Browse files Browse the repository at this point in the history
- Initialiser when extended, now defines the `run!` method on the gem's
  root namespace.
- This is simply a delegation to Kangaru.application.run!, but allows
  calling the application from the target gem's namespace
  (eg SomeGem.run!)
  • Loading branch information
apexatoll committed Sep 24, 2023
1 parent e4abfc8 commit 11c02a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/kangaru/initialiser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ def self.extended(namespace)
root_file = caller[0].gsub(/:.*$/, "")

Kangaru.application = Application.new(root_file:, namespace:).tap(&:setup)

namespace.module_eval do
def self.run!(argv)
Kangaru.application.run!(argv)
end
end
end
end
end
10 changes: 10 additions & 0 deletions spec/features/initialiser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ module SomeGem
it "does not set the Kangaru application reference" do
expect { require_gem }.not_to change { Kangaru.application }.from(nil)
end

it "does not define the run! method in the gem's root module" do
require_gem
expect(SomeGem).not_to respond_to(:run!)
end
end

context "when the target gem extends the initialiser" do
Expand Down Expand Up @@ -70,6 +75,11 @@ module SomeGem
.to(a_kind_of(Kangaru::Application))
end

it "defines the run! method in the gem's root module" do
require_gem
expect(SomeGem).to respond_to(:run!)
end

describe "application reference" do
subject(:application) { Kangaru.application }

Expand Down

0 comments on commit 11c02a3

Please sign in to comment.