Module: Karafka::Constraints
- Defined in:
- lib/karafka/constraints.rb
Overview
Module used to check optional requirements (constraints) that cannot be easily defined by Bundler. Constraints are registered under one of two phases and verified centrally, so all environment requirements live and surface in one place:
:load- verified when karafka itself is required, for requirements independent of the configuration (like ecosystem gems version compatibility):config- verified duringKarafka::App.setupright after the configuration is validated, for requirements that depend on what features are actually enabled (features register those themselves, keeping their specifics out of this generic module)
Class Method Summary collapse
-
.register(name, phase:, &block) ⇒ Object
Registers a constraint for verification.
-
.verify!(phase = :load, config = nil) ⇒ Object
Verifies all the constraints registered for a given phase.
Class Method Details
.register(name, phase:, &block) ⇒ Object
Registers a constraint for verification. Registrations are keyed by name, so re-registration (e.g. when setup runs multiple times in tests) overwrites a previous one instead of accumulating duplicates.
29 30 31 32 33 |
# File 'lib/karafka/constraints.rb', line 29 def register(name, phase:, &block) raise(Errors::UnsupportedCaseError, phase) unless PHASES.include?(phase) constraints[phase][name] = block end |
.verify!(phase = :load, config = nil) ⇒ Object
Verifies all the constraints registered for a given phase
40 41 42 43 44 |
# File 'lib/karafka/constraints.rb', line 40 def verify!(phase = :load, config = nil) raise(Errors::UnsupportedCaseError, phase) unless PHASES.include?(phase) constraints[phase].each_value { |constraint| constraint.call(config) } end |