deadghost
deadghost

Reputation: 5227

Have different code execute depending on lein profiles?

I want my code to behave a tiny bit differently in development than in production; for example, don't actually post things on facebook when the dev profile is activated. Right now I'm thinking I can use robert-hooke to add hooks to functions I don't want run in development; however, how can I check which profiles are activated?

I've also checked out environ which looks great for development vs production configurations but doesn't seem to hit my problem.

I don't think this is a rare problem so if there's already some accepted ways to handle this; great.

Upvotes: 3

Views: 537

Answers (1)

dgtized
dgtized

Reputation: 3382

If you take a look at the luminus guestbook example, it's actually using profiles to set an environment variable :dev, and then environ to read it back from within the application. Environ suggests using the 12 factor app as a model, which makes an argument against grouping configurations inside of the application. Leiningen let's us have the best of both by naming the configuration group external to the actual application. Unfortunately the variable passed to the application is named the same as the profile, and thus groups configurations in the app. Naming it cache.disable but leaving it in the dev profile could fix that.

You could also take a look at isolating dependencies for development. The article has an example near the end using System/getenv that could also use environ as a replacement.

Upvotes: 3

Related Questions