refactor: autoload migration, remove respond_to?, DRY register_model - #34
Merged
Conversation
Replaces all internal `require_relative` calls with Ruby `autoload` declared in the immediate parent namespace's file. Mirrors the V4 pattern across V2 and V3, and finishes V4 by removing its three remaining foundational `require_relative` calls. Replaces two `respond_to?` duck-typing checks with explicit is_a?(Lutaml::Model::TypeContext) || is_a?(Lutaml::Model::Register) and klass.is_a?(Class) && klass <= Lutaml::Model::Serialize checks, so the type contract is verifiable. Removes duplicate Configuration.register_model(...) calls from ~70 per-element files. The version module body is now the single source of truth for registration. Migration surfaced and fixed two pre-existing latent bugs: - V3 module body was not registering Declare and Share (only the per-element file registered them). - V4 module body was not registering Logbase and Domainofapplication (same root cause). Adds spec/mml/code_quality_spec.rb (24 specs) and spec/mml/nested_in_mixed_content_spec.rb (14 specs) that lock in the architectural rules and catch future regressions: - no require_relative / require "mml/..." in lib - no respond_to? / instance_variable_set/get / .send( - no hand-rolled to_h/from_h/serialize/deserialize - every expected element ID registered per version - every autoload constant resolves - entity preservation when Mml::Math is nested in a host mixed_content parent 2964 examples, 0 failures, 36 pending. Rubocop clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
require_relativewith Rubyautoloaddeclared in the immediate parent namespace file (V2, V3, V4 + foundational files). V4's pattern is now consistent across all three versions.respond_to?duck-typing checks with explicitis_a?against known lutaml-model types.Configuration.register_model(...)calls from ~70 per-element files. Version module body is the single source of truth.Bugs surfaced and fixed by the migration
The new lint spec caught two pre-existing latent bugs that were silently relying on per-element registration as the primary (not duplicate) mechanism:
DeclareandShare(onlylib/mml/v3/deprecated_content.rbregistered them).LogbaseandDomainofapplication(only the per-element file registered them).Both are now registered in the version module body. The lint spec prevents recurrence.
Architectural rules now enforced by spec
spec/mml/code_quality_spec.rbfails if any future commit:require_relativefor internal code inlib/mml/**/*.rbrequire "mml/..."for internal pathsrespond_to?,instance_variable_set,instance_variable_get, or.send(for type checking / private accessto_h/from_h/to_hash/from_hash/serialize/deserializeon a model classTest plan
bundle exec rubocop lib/ spec/— 491 files, no offensesspec/mml/code_quality_spec.rb— 24/24 passspec/mml/nested_in_mixed_content_spec.rb— 14/14 pass<mo><</mo>round-trips correctly