Support sampling of validation to make Strict more Lenient
This release exposes configuration options to change the sample rate for validating attributes, parameters, and return values. This new capability means that you can validate all the time in your tests and only 10% of the time in production, for example. Additionally, you can apply different sample rates in performance sensitive areas of code if you need to disable validation entirely:
# Globally
Strict.configure do |c|
c.sample_rate = 0.75 # run validation ~75% of the time
end
Strict.configure do |c|
c.sample_rate = 0 # disable validation (Strict becomes Lenient)
end
Strict.configure do |c|
c.sample_rate = 0 # always run validation
end
# Locally within the block (only applies to the current thread)
Strict.with_overrides(sample_rate: 0) do
# Use Strict as you normally would
Strict.with_overrides(sample_rate: 0.5) do
# Overrides can be nested
end
end
What's Changed
- Bundle update by @kylekthompson in #58
- Expose a configuration for Strict by @kylekthompson in #59
- Make with_overrides thread-safe by @kylekthompson in #60
- Sample validity of attributes, parameters, and returns based on the configuration by @kylekthompson in #61
Full Changelog: v1.4.0...v1.5.0