Class: Invar::Reality::RealityValidator
- Inherits:
-
Object
- Object
- Invar::Reality::RealityValidator
- Defined in:
- lib/invar/reality.rb
Overview
Validates a Reality object
Instance Method Summary collapse
-
#initialize(configs_schema, secrets_schema) ⇒ RealityValidator
constructor
A new instance of RealityValidator.
- #validate(configs, secrets) ⇒ Object
Constructor Details
#initialize(configs_schema, secrets_schema) ⇒ RealityValidator
Returns a new instance of RealityValidator.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/invar/reality.rb', line 172 def initialize(configs_schema, secrets_schema) configs_schema ||= Dry::Schema.define env_schema = build_env_schema @schema = Dry::Schema.define do config.validate_keys = true required(:configs).hash(configs_schema & env_schema) if secrets_schema required(:secrets).hash(secrets_schema) else required(:secrets) end end end |
Instance Method Details
#validate(configs, secrets) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/invar/reality.rb', line 189 def validate(configs, secrets) validation = @schema.call(configs: configs.to_h, secrets: secrets.to_h) return true if validation.success? errs = validation.errors..collect do || [.path.collect do |p| ":#{ p }" end.join(' / '), .text].join(' ') end raise SchemaValidationError, <<~ERR Validation errors: #{ errs.join("\n ") } ERR end |