Last active
August 29, 2015 14:01
-
-
Save joelkuiper/e9d34f3053fa795a5cd3 to your computer and use it in GitHub Desktop.
Loading a var outside of classpath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn get-var | |
[ns sym] | |
(let [path (str (s/replace ns "." "/") "/" sym ".clj") | |
f (io/as-file (io/resource path))] | |
(when (not (nil? f)) | |
(load-string (slurp f)) | |
(if-let [s (find-var (symbol (str ns "/" sym)))] | |
(var-get s) | |
nil)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assume the ns processors.twitter is in "resources/processors/twitter.clj" which contains the var "twitter"
then call
(get-var "processors.twitter" "twitter")
will return nil otherwise