diff --git a/config.lisp b/config.lisp index e746639..0b365b3 100644 --- a/config.lisp +++ b/config.lisp @@ -6,7 +6,7 @@ (:use :common-lisp) (:export #:base #:root #:env-data #:env-keys #:env-prefix #:env-path - #:add #:children #:parent + #:add #:children #:env-slots #:parent #:hash-to-slots)) (in-package :scopes/config) @@ -52,12 +52,14 @@ ;;;; config base class (defclass base (common) - ((parent :reader parent + ((env-slots :reader env-slots :initform nil :allocation :class) + (parent :reader parent :initarg :parent))) (defmethod initialize-instance :after ((cfg base) &key parent &allow-other-keys) (if parent - (push cfg (children parent)))) + (push cfg (children parent)) + (hash-to-slots (env-data cfg) cfg (env-slots cfg)))) (defmethod (setf parent) ((cfg base) (parent common)) (push cfg (children parent))) diff --git a/core/core.lisp b/core/core.lisp index c2d4ffb..7992ae2 100644 --- a/core/core.lisp +++ b/core/core.lisp @@ -15,8 +15,8 @@ (defclass config (config:root) ()) -(defun root-config () - (make-instance 'config)) +(defun root-config (&rest params) + (apply #'make-instance 'config params)) (defclass service-config (config:base) ((name :reader name :initarg :name) diff --git a/test/etc/config-web.lisp b/test/etc/config-web.lisp index 1cd8d4b..781a3f3 100644 --- a/test/etc/config-web.lisp +++ b/test/etc/config-web.lisp @@ -2,8 +2,7 @@ (in-package :scopes/test-web) -(setf *config* - (make-instance 'config:root :env-keys '(:address :port))) +(setf *config* (core:root-config :env-keys '(:address :port))) (make-instance 'server:config :parent *config* :port "8899") diff --git a/test/test-config.lisp b/test/test-config.lisp index c14d909..e514fa1 100644 --- a/test/test-config.lisp +++ b/test/test-config.lisp @@ -19,12 +19,10 @@ (config:env-path :initform (t:test-path ".test.env")))) (defclass child-config (config:base) - ((user :accessor user :initarg :user) + ((config:env-slots :initform '(user password)) + (user :accessor user :initarg :user) (password :accessor password :initarg :password))) -(defmethod initialize-instance :after ((cfg child-config) &key &allow-other-keys) - (config:hash-to-slots (config:env-data cfg) cfg '(user password))) - (defun run () (let ((*config* nil) (t:*test-suite* (t:test-suite "config"))) diff --git a/test/test-core.lisp b/test/test-core.lisp index 1676f94..d0551da 100644 --- a/test/test-core.lisp +++ b/test/test-core.lisp @@ -64,6 +64,6 @@ (msg (message:simple-message '(:test :dummy) "dummy payload")) (msg-exp (message:simple-message '(:test :dummy) "dummy payload"))) (expect rcvr msg-exp) - (== (core:name (core:config rcvr)) :test-receiver) + (== (core:name rcvr) :test-receiver) (core:send rcvr msg) )) diff --git a/test/test-web.lisp b/test/test-web.lisp index 612e6a3..47f654b 100644 --- a/test/test-web.lisp +++ b/test/test-web.lisp @@ -3,6 +3,7 @@ (defpackage :scopes/test-web (:use :common-lisp) (:local-nicknames (:config :scopes/config) + (:core :scopes/core) (:client :scopes/web/client) (:server :scopes/web/server) (:t :scopes/testing)) diff --git a/web/server.lisp b/web/server.lisp index dc04d3b..1d089e2 100644 --- a/web/server.lisp +++ b/web/server.lisp @@ -9,12 +9,10 @@ (in-package :scopes/web/server) (defclass config (config:base) - ((address :reader address :initarg :address :initform "localhost") + ((config:env-slots :initform '(address port)) + (address :reader address :initarg :address :initform "localhost") (port :reader port :initarg :port :initform "8888"))) -(defmethod initialize-instance :after ((cfg config) &key &allow-other-keys) - (config:hash-to-slots (config:env-data cfg) cfg '(address port))) - ;;;; listener = server process (defvar *listener* nil)