Skip to content

Refactor: autoload, OOP cleanup, and spec improvements#420

Open
ronaldtse wants to merge 4 commits into
mainfrom
refactor/autoload-oop-cleanup
Open

Refactor: autoload, OOP cleanup, and spec improvements#420
ronaldtse wants to merge 4 commits into
mainfrom
refactor/autoload-oop-cleanup

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Changes

Architecture

  • Autoload conversion: All internal require "metanorma/cli/*" converted to Ruby autoload in parent namespace files. Created lib/metanorma/cli/commands.rb for the Commands namespace autoloads.
  • FlavorMethods module: cli/flavor.rb converted from reopening the Command class to a proper FlavorMethods module, included via include FlavorMethods.
  • ConfigExtractor extraction: The export_config_* methods (~100 lines) extracted from the flavor helpers into a dedicated Metanorma::Cli::ConfigExporter class.

Code Quality

  • Removed require_relative "flavor" from command.rb (last require_relative in lib/)
  • Removed all internal requires from individual files (autoloaded from namespace files)
  • Simplified public_send(:[], h)acc[h] and public_send(:[]=, ...)acc[...] = value in Commands::Config
  • Replaced manifest[:template]&.public_send(node.to_s) with direct attribute access in SiteGenerator
  • Made collection_file? and select_source_collection_files public query methods

Specs

  • Replaced double() with instance_double() (type-checked) in collection and compiler specs
  • Removed send() on private methods in site_generator_spec
  • Added spec for new ConfigExporter class

Note

stringify_all_keys.rb is dead code (require commented out everywhere) — flagged for removal in a follow-up.

@ronaldtse
ronaldtse force-pushed the refactor/autoload-oop-cleanup branch 3 times, most recently from b6455d7 to 6629101 Compare June 8, 2026 06:45
Comment thread .github/workflows/notify.yml Fixed
Comment thread .github/workflows/rake.yml Fixed
Comment thread .github/workflows/release.yml Fixed
@opoudjis

opoudjis commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

@ronaldtse Merged main into this (a ton of discrepancies), it failed badly, you will need to get it working. Not to be included in this release, marking as draft until it matures.

As I have no idea what you are doing, merging main into this PR to make it ready for merging is your responsibillity...

@opoudjis
opoudjis marked this pull request as draft June 8, 2026 10:33
@ronaldtse
ronaldtse force-pushed the refactor/autoload-oop-cleanup branch 2 times, most recently from e1fc4af to 8b47b85 Compare June 10, 2026 03:15
@ronaldtse
ronaldtse force-pushed the refactor/autoload-oop-cleanup branch from 8b47b85 to 400b7d0 Compare June 10, 2026 03:43
@ronaldtse
ronaldtse marked this pull request as ready for review June 10, 2026 09:41
@ronaldtse

Copy link
Copy Markdown
Contributor Author

@opoudjis this is ready.

opoudjis added 2 commits June 16, 2026 01:56
The main->branch merge surfaced three breakages, all on the refactor side:

1. site_generator_spec.rb: the refactor moved let(:output_directory) into
   each context but missed "with output format extensions" (the #418 group),
   so output_directory was undefined there (5 failures). Add the let.

2. ConfigExporter::FLAVOR_FILE_PATTERNS was a stale duplicate of
   flavor.rb's EXPORT_CONFIG_FLAVOR_FILES and lacked the .xsl/.yaml globs
   merged from #421/#423, so export-config dropped flavor XSLT and .yaml
   i18n files (1 failure). Add the globs to the live ConfigExporter list,
   and delete the now-dead flavor.rb export methods + constant (no callers
   since export_config routes through ConfigExporter) to remove the
   duplication that caused the divergence. This also clears the 4 rubocop
   offenses that lived in that dead block.

3. export_config_spec.rb: collapse the per-file File.exist? assertions into
   a loop, clearing the two over-long lines and the redundant Dir.exist?
   guard before FileUtils.rm_rf.
@opoudjis

Copy link
Copy Markdown
Contributor

Pushed f3d79e5 to fix the red CI. The main → branch merge pulled in the #418 (--extensions) and #421/#423 (export-config .xsl/.yaml) work, and three things diverged against the refactor:

1. site_generator_spec.rb — 5 failures (NameError: undefined ... 'output_directory'). The refactor replaced the single top-level let(:output_directory) with per-context copies (#select_source_collection_files, without manifest file, with manifest file, custom site template) but the merged context "with output format extensions" never got one. Added it.

2. export_config_spec.rb — 1 failure (.xsl not exported). Root cause is a duplicated glob list: the new ConfigExporter::FLAVOR_FILE_PATTERNS was a stale copy of flavor.rb's EXPORT_CONFIG_FLAVOR_FILES, predating the .xsl/.yaml globs added in #421/#423. export-config routes through ConfigExporter (command.rb:189), so the flavor.rb copy — which did have the globs — was dead. Synced the globs into the live ConfigExporter list and deleted the dead flavor.rb export methods + constant (no remaining callers) so the duplication can't diverge again. That removal also cleared the 4 rubocop offenses that lived in the dead block.

3. rubocop — 7 offenses. 4 were in the dead flavor.rb block (gone with #2); the other 3 were over-long lines + a redundant Dir.exist? guard in export_config_spec.rb, collapsed into a loop.

Verified locally: config_exporter_spec green, export_config_spec:20 green (exports .xsl + .yaml), rubocop clean on all four files, and the extensions examples now execute past the NameError (they hit a macOS-only Errno::EPERM ./TemporaryItems temp-dir artifact in my local fs that the CI runners don't have — CI will confirm those). The duplication between ConfigExporter and the old flavor.rb path is worth keeping an eye on; collapsing fully onto ConfigExporter is the right end state.

🤖

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.

3 participants