A common requirement in Grails plugins and applications is to determine whether a config option is set and if not, to use a default. For example:
where grailsApplication.config is an instance of ConfigObject. This works great - except when it comes to boolean values (or any type with special Groovy Truth behaviour). What if I want to check whether a boolean rabbitmq.myService.transactional setting has a value or not? Using the above code, the left-hand side of the Elvis operator would be assigned both when the option is not set and when it has a value of false.
To distinguish between an explicit value of false and an unset config option, we have to resort to code like:
That's neither concise nor elegant, and checking the type of the return value is too dependent on the internal implementation of ConfigObject.
I suggest that we add an extra method (perhaps called isSet()) that allows code to readily determine whether a config options has a value or not:
Perhaps we should also support rabbitConfig.isSet("myService.transactional")? In some ways I think that adds complexity with little benefit, but it may be useful to people.