From 6f245675c304432cd640f30027844e95b2f0cb80 Mon Sep 17 00:00:00 2001 From: Chris Welham <71787007+apexatoll@users.noreply.github.com> Date: Wed, 27 Sep 2023 01:54:11 +0100 Subject: [PATCH] Implement application config --- lib/kangaru/application.rb | 4 ++++ sig/kangaru/application.rbs | 4 ++++ spec/kangaru/application_spec.rb | 15 +++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/lib/kangaru/application.rb b/lib/kangaru/application.rb index 25b6a82..819b28a 100644 --- a/lib/kangaru/application.rb +++ b/lib/kangaru/application.rb @@ -12,6 +12,10 @@ def initialize(name:, dir:, namespace:) @namespace = namespace end + def config + @config ||= Config.new + end + def setup autoloader.setup end diff --git a/sig/kangaru/application.rbs b/sig/kangaru/application.rbs index b5d0f5b..90c0c15 100644 --- a/sig/kangaru/application.rbs +++ b/sig/kangaru/application.rbs @@ -6,8 +6,12 @@ module Kangaru attr_reader dir: String attr_reader namespace: Module + @config: Config + def initialize: (name: String, dir: String, namespace: Module) -> void + def config: -> Config + def setup: -> void def run!: (Array[String]) -> void diff --git a/spec/kangaru/application_spec.rb b/spec/kangaru/application_spec.rb index 82f09e4..3078d62 100644 --- a/spec/kangaru/application_spec.rb +++ b/spec/kangaru/application_spec.rb @@ -9,6 +9,21 @@ before { stub_const "SomeApp", Module.new } + describe "#config" do + subject(:config) { application.config } + + it "returns a config object" do + expect(config).to be_a(Kangaru::Config) + end + + it "caches the config object" do + expect { config } + .to change { application.instance_variable_defined?(:@config) } + .from(false) + .to(true) + end + end + describe "#setup" do subject(:setup) { application.setup }