You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because of performance requirements we want our contract checks to only run in development/testing.
The default is that contracts are always on. Is it possible to reverse that? Off by default, on with a switch?
The reason I ask is that it is difficult to automatically guarantee that contracts are not running in production, ie the env variable is set and used correctly. The reverse is easy.
Or to rephrase my question/request. Is there an easy way make sure contracts are off in production. Or maybe we can configure it ourselves?
The text was updated successfully, but these errors were encountered:
Are you referring to the NO_CONTRACTS env var? That is the easiest way to make sure that contracts aren't running. But you can also specify your own override callback instead of using the default one with override_failure_callback. Here's a simple example:
require"contracts"includeContractsContract.override_failure_callbackdo |data|
pdatafalse# don't run the function since the contract failedendContractNum=>Numdefincraa + 1endincr("Asdas")# will just print a hash instead of throwing an error
Thanks for the feedback (sorry for the delay because holiday ;).
Yes I am referring to the NO_CONTRACTS env var. The problem is that I am (for now only) using the contracts in a gem that is used in another gem. Having the coupling via an ENV var means, that the gem that is using my gem with contracts needs to know about contracts and needs to set the ENV var (AFAIK).
So I was looking for a way to locally disable the contract checking in production from the gem that is using contracts. Performance is critical to our app that's why I am disabling the checking.
I guess the only way to do that is by monkey_patching the following methods (the ones that use NO_CONTRACTS):
InvariantExtension#invariant to return nil
MethodHandler#ignore_decorators to return true
But then I have to check this every time contracts.gem updates.
Another way might be to make contracts a development dependency and complety monkey patch the Contract method to do nothing...?
Am I making sense? :) Maybe I want to solve this in the wrong way...
Because of performance requirements we want our contract checks to only run in development/testing.
The default is that contracts are always on. Is it possible to reverse that? Off by default, on with a switch?
The reason I ask is that it is difficult to automatically guarantee that contracts are not running in production, ie the env variable is set and used correctly. The reverse is easy.
Or to rephrase my question/request. Is there an easy way make sure contracts are off in production. Or maybe we can configure it ourselves?
The text was updated successfully, but these errors were encountered: