I was wondering if there’s possibility to sort of repeat this Ruby behavior but in crystal (and at compile time):
begin
require "some_gem"
require "./ext_for_some_gem" #< Require my code only if some_gem is available
rescue LoadError => e
#Do not add my flavored code as the optional gem is not available
end
Which may look in crystal:
{% if require_exists?("some_shard") %}
require "some_shard"
require "./ext_for_some_shard"
{% end %}
This will allow also to create more beautiful compiler error code like this:
require "a_shard/ext/kemal"
# ^~~~ ERROR: You required ext/kemal but kemal wasn't found in your
# shards.yml ! Please install kemal first by adding:
# -----
# kemal:
# github: kemalcr/kemal
# -----
# in your shards.yml
I don’t know if anything like this exists already in the macro system. Any thought about it?