Class: Coradoc::Validation::SchemaGenerator
- Inherits:
-
Object
- Object
- Coradoc::Validation::SchemaGenerator
- Defined in:
- lib/coradoc/validation.rb
Overview
Schema generator from CoreModel types
Automatically generates validation schemas from Lutaml::Model classes. This enables automatic validation based on model structure.
Class Method Summary collapse
-
.generate(model_class, required: [], ignored: [], custom_rules: {}) ⇒ Schema
Generate a validation schema from a CoreModel class.
-
.map_type(type) ⇒ Class+
Map Lutaml::Model type to Ruby class.
Class Method Details
.generate(model_class, required: [], ignored: [], custom_rules: {}) ⇒ Schema
Generate a validation schema from a CoreModel class
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'lib/coradoc/validation.rb', line 481 def generate(model_class, required: [], ignored: [], custom_rules: {}) return nil unless model_class.respond_to?(:attributes) # Pre-compute attribute definitions before the schema block attribute_defs = compute_attribute_definitions( model_class, required, ignored, custom_rules ) Schema.define do attribute_defs.each do |name, type, , is_required| if is_required required name, type: type, ** else optional name, type: type, ** end end end end |
.map_type(type) ⇒ Class+
Map Lutaml::Model type to Ruby class
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 |
# File 'lib/coradoc/validation.rb', line 504 def map_type(type) # Handle Lutaml::Model type classes by name type_name = type.to_s case type_name when 'Lutaml::Model::Type::String' String when 'Lutaml::Model::Type::Integer' Integer when 'Lutaml::Model::Type::Float' Float when 'Lutaml::Model::Type::Boolean' [TrueClass, FalseClass] when 'Lutaml::Model::Type::Date' Date when 'Lutaml::Model::Type::Time' Time when 'Lutaml::Model::Type::DateTime' Time when 'Lutaml::Model::Type::Hash' Hash when 'Lutaml::Model::Type::Array' Array else # For non-Lutaml types (like CoreModel::Base), return the type itself type.is_a?(Class) ? type : Object end end |