move update of slot values to separate function
This commit is contained in:
parent
d9819cbe2e
commit
5a63a1034d
2 changed files with 10 additions and 6 deletions
10
config.lisp
10
config.lisp
|
@ -5,7 +5,7 @@
|
||||||
(defpackage :scopes/config
|
(defpackage :scopes/config
|
||||||
(:use :common-lisp)
|
(:use :common-lisp)
|
||||||
(:export #:base
|
(:export #:base
|
||||||
#:env-data #:env-keys #:env-prefix #:env-path))
|
#:env-data #:env-keys #:env-prefix #:env-path #:hash-to-slots))
|
||||||
|
|
||||||
(in-package :scopes/config)
|
(in-package :scopes/config)
|
||||||
|
|
||||||
|
@ -34,3 +34,11 @@
|
||||||
(if env-val
|
(if env-val
|
||||||
(setf (gethash sl data) env-val)
|
(setf (gethash sl data) env-val)
|
||||||
(setf (gethash sl data) dotenv-val))))))
|
(setf (gethash sl data) dotenv-val))))))
|
||||||
|
|
||||||
|
(defun hash-to-slots (ht obj slots)
|
||||||
|
(if ht
|
||||||
|
(dolist (sl slots)
|
||||||
|
(let* ((key (intern (string sl) :keyword))
|
||||||
|
(val (gethash key ht)))
|
||||||
|
(if val
|
||||||
|
(setf (slot-value obj sl) val))))))
|
||||||
|
|
|
@ -21,11 +21,7 @@
|
||||||
(password :accessor password :initarg :password)))
|
(password :accessor password :initarg :password)))
|
||||||
|
|
||||||
(defmethod initialize-instance :after ((cfg test-config) &key &allow-other-keys)
|
(defmethod initialize-instance :after ((cfg test-config) &key &allow-other-keys)
|
||||||
(let* ((data (config:env-data cfg))
|
(config:hash-to-slots (config:env-data cfg) cfg '(user password)))
|
||||||
(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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue