Skip to content

Instantly share code, notes, and snippets.

@joelkuiper
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelkuiper/e9d34f3053fa795a5cd3 to your computer and use it in GitHub Desktop.
Save joelkuiper/e9d34f3053fa795a5cd3 to your computer and use it in GitHub Desktop.
Loading a var outside of classpath
(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))))
@joelkuiper
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment