This looks simple and useful, thanks!

Supposing I had a function that called this library, how could I go about 
testing it easily? That is, the configuration file becomes implicitly an 
input to the function, one that I'd like to be able to control from my 
tests. Perhaps something like this could be used to provide or override 
config settings dynamically:

(with-config {:username "bogus"}
  (...))

I'm not trying to open the dynamic scoping can of worms here; this library 
clearly is a choice for people already willing to work in that way. 


On Thursday, May 2, 2013 9:40:29 PM UTC+9, Adam Clements wrote:
>
> A very simple library for loading application level config from a 
> configuration file in a nice way, with caching and reloading functionality. 
>
> Any other configuration libraries I found were either massively overkill 
> for my needs (full on validation schemas built in), too complicated to set 
> up and pass around or involved simply read-evaling a whole namespace which 
> could be insecure depending where you get your config.
>
> Simple but useful - I found myself duplicating this code in almost all my 
> projects before making it into a library! Well tested and documented, 
> there are very few moving parts so I expect this to stay stable and not 
> really change over time.
>
> Source:  https://github.com/TouchType/conf-er
> Clojars: [conf-er "1.0.1"]
>
> The idea is to have a single configuration file which consists of a 
> keyworded map, you then look up individual properties with nested keywords, 
> for example your config file looks like this (simple EDN map):
>
> ;; my-config.conf
>> {:username "joe.bloggs"
>>  :password "letmein"
>>  :database {:host "127.0.0.1"
>>             :port 1234}
>>  :my.library/number 42}
>
>
> And then look up the configuration from anywhere within your program! 
> Simply include the conf-er namespace
>
> (use 'conf-er) 
>
>
>> (config :username) => "joe.bloggs"
>> (configured? :database) => true
>> (config :database) => {:host "127.0.0.1" :port 1234}
>> (config :database :port) => 1234
>
>
>
> Tell your program where to find the configuration file from your leiningen 
> project.clj during development, or if you are distributing a jar then add 
> the property onto the java command line call:
>>
>> ...
>> :jvm-opts ["-Dconfig=~/my-config.conf"]
>> ...
>
>
> (config :database :connections) => (Exception "Couldn't find :database 
> :connections in configuration file")
> (opt-config :database :connections) => nil
>
> If you use this from within a library, you must namespace your 
> configuration in case the application using your library also wishes to use 
> conf-er. You can do this like so:
>
> (ns my.library
>>   (:require [conf-er :refer [config]]))
>> (config ::number) => 42
>
>  
> Here :number will expand out to the namespaced keyword :my.library/number, 
> which we put in our configuration file earlier.
>
> Hope this is of use to some people.
>
> Adam 
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to