integrant

theeternalpulse 2019-07-09T03:28:46.008400Z

I'm toying with using integrant and would like some advice. I am using config data generated by a function so that I can programatically set defaults and use some fns to generate some data I'm injecting to the different init-keys. I am aware I can replace a lot of this by just doing an edn and creating more init-keys or prep-keys to further condition that edn data for the actual runtime code. is there any benefit to doing this. here is my config.clj https://github.com/dantheobserver/parrot-api/blob/implement.memory.store/src/clj/dantheobserver/parrot_api/config.clj

sandqvist 2019-07-13T07:08:43.014300Z

I think your way is good. I personally use aero to read the configuration from a file and handle different run profiles (dev/test/staging/production) all of which have their own defaults and override possibilities.

theeternalpulse 2019-07-13T12:05:08.014700Z

I did look at some other files and noticed that you can include function calls. I didn't understand why he used the hash symbol in front of the function them saw that it was a way to store function calls in edn. That makes it a lot easier to move to a file since some of my config relies on env vars.

theeternalpulse 2019-07-13T12:05:22.014900Z

Thanks for responding btw

sandqvist 2019-07-13T16:22:58.015100Z

(defmethod aero.core/reader 'envr
  [_ _ s]
  (env s))

(defmethod aero.core/reader 'component
  [opts tag value]
  (integrant/ref value))

sandqvist 2019-07-13T16:23:22.015300Z

I use the above readers with aero to read the config with environment variables.

theeternalpulse 2019-07-14T00:21:18.023400Z

I was wondering, if I'm referencing integrant.core :as ig why does aero not look for that when it attempts to read it.

theeternalpulse 2019-07-14T00:21:34.023600Z

if I have #ig/ref in my config

theeternalpulse 2019-07-14T01:59:04.023800Z

I guess I have to do something like

(binding [*data-readers* {'ig/ref ig/ref}]
  (aero/read-config (<http://clojure.java.io/resource|clojure.java.io/resource> "config.edn")))

sandqvist 2019-07-14T07:52:06.024Z

You can just defmethod the reader, take my snippet above and replace component with ig/ref. Aero has its own multimethod for adding readers.

theeternalpulse 2019-07-14T08:58:35.024200Z

Cool I think I got a good solution using aero, consolidates things nicely, just took some time experimenting

dangercoder 2019-07-16T17:24:44.044400Z

@theeternalpulse @sandqvist thanks for the "secret sauce" I stumbled upon the same problem with environment variables. I'll use Aero too 🙂

dangercoder 2019-07-16T18:07:15.044600Z

It is almost better than christmas morning

theeternalpulse 2019-07-17T19:58:27.044900Z

@jarvinenemil I should push my branch with the aero changes, it requires some divergences with integrant, but I like the ability to add edn tag readers easily. My config.clj now is just the readers for some edn tags and a facade to read the config, but the config itself is in edn

dangercoder 2019-07-18T05:37:02.045100Z

@theeternalpulse It would be awesome to see your aero changes, thanks for sharing your work!

theeternalpulse 2019-07-09T03:31:11.010900Z

also, one thing I don't get, is that in the talk I watched about it, it says that integrant loads the namespaces of the various keys so you don't have to require them. I'm not sure you had to do that for namespaced keywords. Also if a reference a keyword as my.namespace/some-key in my.namespace can I just do (ig/init-key ::some-key for short?

sandqvist 2019-07-13T07:10:10.014500Z

That is how i do it.