Skip to content

refactor: autoload migration, remove respond_to?, DRY register_model - #34

Merged
ronaldtse merged 1 commit into
mainfrom
refactor/autoload-no-respond-to
Jul 22, 2026
Merged

refactor: autoload migration, remove respond_to?, DRY register_model#34
ronaldtse merged 1 commit into
mainfrom
refactor/autoload-no-respond-to

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Summary

  • Replaces all internal require_relative with Ruby autoload declared in the immediate parent namespace file (V2, V3, V4 + foundational files). V4's pattern is now consistent across all three versions.
  • Replaces two respond_to? duck-typing checks with explicit is_a? against known lutaml-model types.
  • Removes duplicate Configuration.register_model(...) calls from ~70 per-element files. Version module body is the single source of truth.
  • Adds two new spec files (38 specs total) that lock in the architectural rules as lint checks + entity-preservation regression coverage.

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:

  • V3 module body was not registering Declare and Share (only lib/mml/v3/deprecated_content.rb registered them).
  • V4 module body was not registering Logbase and Domainofapplication (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.rb fails if any future commit:

  • introduces require_relative for internal code in lib/mml/**/*.rb
  • introduces require "mml/..." for internal paths
  • uses respond_to?, instance_variable_set, instance_variable_get, or .send( for type checking / private access
  • defines hand-rolled to_h/from_h/to_hash/from_hash/serialize/deserialize on a model class
  • drops registration for any expected element ID
  • references an autoload constant that cannot resolve

Test plan

  • 2964 examples, 0 failures, 36 pending
  • bundle exec rubocop lib/ spec/ — 491 files, no offenses
  • spec/mml/code_quality_spec.rb — 24/24 pass
  • spec/mml/nested_in_mixed_content_spec.rb — 14/14 pass
  • Smoke-test all three versions: entity preservation in <mo>&lt;</mo> round-trips correctly

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.
@ronaldtse
ronaldtse merged commit 7800b80 into main Jul 22, 2026
14 checks passed
@ronaldtse
ronaldtse deleted the refactor/autoload-no-respond-to branch July 22, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant