proof of concept: set / overwrite slots from env-data
This commit is contained in:
parent
ebd7275b8a
commit
d9819cbe2e
1 changed files with 13 additions and 2 deletions
|
@ -16,7 +16,16 @@
|
||||||
|
|
||||||
(defclass test-config (config:base)
|
(defclass test-config (config:base)
|
||||||
((config:env-keys :initform '(:user :password))
|
((config:env-keys :initform '(:user :password))
|
||||||
(config:env-path :initform (t:test-path ".test.env"))))
|
(config:env-path :initform (t:test-path ".test.env"))
|
||||||
|
(user :accessor user :initarg :user)
|
||||||
|
(password :accessor password :initarg :password)))
|
||||||
|
|
||||||
|
(defmethod initialize-instance :after ((cfg test-config) &key &allow-other-keys)
|
||||||
|
(let* ((data (config:env-data cfg))
|
||||||
|
(u (if data (gethash :user data)))
|
||||||
|
(pw (if data (gethash :password data))))
|
||||||
|
(if u (setf (user cfg) u))
|
||||||
|
(if pw (setf (password cfg) pw))))
|
||||||
|
|
||||||
(defun run ()
|
(defun run ()
|
||||||
(let ((*config* nil)
|
(let ((*config* nil)
|
||||||
|
@ -35,4 +44,6 @@
|
||||||
(t:deftest test-env-override ()
|
(t:deftest test-env-override ()
|
||||||
(let ((data (config:env-data *config*)))
|
(let ((data (config:env-data *config*)))
|
||||||
(== (gethash :user data) "user-from-env-file")
|
(== (gethash :user data) "user-from-env-file")
|
||||||
(== (gethash :password data) "very_secret")))
|
(== (gethash :password data) "very_secret")
|
||||||
|
(== (user *config*) "user-from-env-file")
|
||||||
|
(== (password *config*) "very_secret")))
|
||||||
|
|
Loading…
Add table
Reference in a new issue