Embed version from shard.yml into code?

Is there a “best practice” way to extract the version from a shard.yml file and automatically embed it into the code during compilation?

Or is Macros#system the way to go? Which would require a dependency on external tools, which I’m trying to avoid.

It’s fairly common for people to do like:

VERSION = {{ `shards version #{__DIR__}`.chomp.stringify }}

Which you can do if you want, I personally just find it easier to have it part of my process to manually update when I’m releasing a new version of a shard. Which could be automated fairly easily as part of your release process as well.

1 Like