Module: Securial::Config::Validation
Overview
Configuration validation and verification utilities.
This module provides methods to validate Securial configuration objects against the defined schema, ensuring type safety, required field presence, and business logic constraints are met before the application starts.
Instance Method Summary collapse
-
#raise_error(msg) ⇒ void
private
private
Logs error message and raises configuration error.
-
#validate_all!(securial_config) ⇒ void
Validates all configuration settings against the schema.
-
#validate_password_lengths!(config) ⇒ void
private
private
Validates password length configuration constraints.
-
#validate_required_fields!(signature, config) ⇒ void
private
private
Validates that all required configuration fields are present.
-
#validate_types_and_values!(signature, config) ⇒ void
private
private
Validates types and value constraints for configuration fields.
Instance Method Details
#raise_error(msg) ⇒ void (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Logs error message and raises configuration error.
Provides a consistent way to handle validation failures by logging the error at fatal level and raising the appropriate exception.
154 155 156 157 |
# File 'lib/securial/config/validation.rb', line 154 def raise_error(msg) Securial.logger.fatal msg raise Securial::Error::Config::InvalidConfigurationError, msg end |
#validate_all!(securial_config) ⇒ void
This method returns an undefined value.
Validates all configuration settings against the schema.
Performs comprehensive validation of the provided configuration object, including required field checks, type validation, value constraints, and cross-field dependency validation.
49 50 51 52 53 54 55 |
# File 'lib/securial/config/validation.rb', line 49 def validate_all!(securial_config) signature = Securial::Config::Signature.config_signature validate_required_fields!(signature, securial_config) validate_types_and_values!(signature, securial_config) validate_password_lengths!(securial_config) end |
#validate_password_lengths!(config) ⇒ void (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Validates password length configuration constraints.
Ensures that password minimum length does not exceed maximum length, which would create an impossible constraint for users.
138 139 140 141 142 |
# File 'lib/securial/config/validation.rb', line 138 def validate_password_lengths!(config) if config.password_min_length > config.password_max_length raise_error("password_min_length cannot be greater than password_max_length.") end end |
#validate_required_fields!(signature, config) ⇒ void (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Validates that all required configuration fields are present.
Checks both unconditionally required fields and conditionally required fields based on other configuration values.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/securial/config/validation.rb', line 70 def validate_required_fields!(signature, config) signature.each do |key, | value = config.send(key) required = [:required] if required == true && value.nil? raise_error("#{key} is required but not provided.") elsif required.is_a?(String) # Handle conditional requirements based on other config values dynamic_required = config.send(required) signature[key][:required] = dynamic_required if dynamic_required && value.nil? raise_error("#{key} is required but not provided when #{required} is true.") end end end end |
#validate_types_and_values!(signature, config) ⇒ void (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Validates types and value constraints for configuration fields.
Ensures that configuration values match their expected types and fall within acceptable ranges or allowed value sets.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/securial/config/validation.rb', line 99 def validate_types_and_values!(signature, config) signature.each do |key, | next unless signature[key][:required] value = config.send(key) types = Array([:type]) # Type validation unless types.any? { |type| value.is_a?(type) } raise_error("#{key} must be of type(s) #{types.join(', ')}, but got #{value.class}.") end # Duration-specific validation if [:type] == ActiveSupport::Duration && value <= 0 raise_error("#{key} must be a positive duration, but got #{value}.") end # Numeric value validation if [:type] == Numeric && value < 0 raise_error("#{key} must be a non-negative numeric value, but got #{value}.") end # Allowed values validation if [:allowed_values] && [:allowed_values].exclude?(value) raise_error("#{key} must be one of #{[:allowed_values].join(', ')}, but got #{value}.") end end end |