Ruby Script Audit Tracking
This document tracks the progress of auditing each Ruby script in the ebook conversion system before refactoring and eventual migration to Elixir.
Audit Status Overview
| Script Name | Path | Audit Status | Execution Status | Functionality Score | Code Quality Score | Test Coverage | Documentation Score | Refactoring Priority | Migration Complexity | Notes |
|---|---|---|---|---|---|---|---|---|---|---|
| CommandExecutor | lib/system/command_executor.rb | Complete | Passes | Good | Medium | Low | Poor | High | Medium | Foundation for system commands |
| CommandValidator | lib/system/command_validator.rb | Complete | Passes | Poor | Poor | Unknown | None | High | Low | Significant overlap with CommandExecutor |
| EbookValidator | scripts/ebook_validator.rb | Complete | Conditional | Partial | Adequate | Low | Poor | Medium | Medium | Standalone validation utility |
| BookDeployer | scripts/book_deployer.rb | Complete | Passes | Complete | Good | Unknown | Minimal | Medium | Low | Deployment utility |
| MetadataLoader | scripts/metadata_loader.rb | Complete | Passes with warnings | Partial | Poor | Unknown | None | High | Medium | Used by multiple components |
| BuildEbooks | scripts/build_ebooks.rb | Complete | Conditional | Unknown | Good | Unknown | Poor | High | High | Central build coordination |
| CommandRunner | lib/book_processing/utilities/command_runner.rb | Complete | Passes | Good | Good | Low | Good | High | Medium | Extends CommandExecutor |
| MetadataHandler | lib/metadata_handler.rb | Pending | - | - | - | - | - | - | - | - |
| LoggerSetup | lib/logger_setup.rb | Pending | - | - | - | - | - | - | - | - |
| PdfBuilder | lib/book_processing/builders/pdf_builder.rb | Pending | - | - | - | - | - | - | - | - |
| EbookFormatsBuilder | lib/book_processing/builders/ebook_formats_builder.rb | Pending | - | - | - | - | - | - | - | - |
| LatexToWikijs | lib/book_processing/converters/latex_to_wikijs.rb | Pending | - | - | - | - | - | - | - | - |
| QualityChecker | lib/book_processing/quality_checker.rb | Pending | - | - | - | - | - | - | - | - |
| setup_project.rb | scripts/utils/setup_project.rb | Pending | - | - | - | - | - | - | - | - |
| setup_tools.rb | scripts/utils/setup_tools.rb | Pending | - | - | - | - | - | - | - | - |
| generate_cover_svg.rb | scripts/utils/generate_cover_svg.rb | Pending | - | - | - | - | - | - | - | - |
Dependency Map
graph TD
CommandExecutor[System::CommandExecutor]
CommandValidator[System::CommandValidator]
CommandRunner[BookProcessing::Utilities::CommandRunner]
PdfBuilder[BookProcessing::Builders::PdfBuilder]
EbookBuilder[BookProcessing::Builders::EbookFormatsBuilder]
LatexToWikijs[BookProcessing::Converters::LatexToWikijs]
QualityChecker[BookProcessing::QualityChecker]
BuildEbooks[scripts/build_ebooks.rb]
SetupTools[scripts/utils/setup_tools.rb]
SetupProject[scripts/utils/setup_project.rb]
MetadataHandler[lib/metadata_handler.rb]
MetadataLoader[scripts/metadata_loader.rb]
BookDeployer[scripts/book_deployer.rb]
EbookValidator[scripts/ebook_validator.rb]
LoggerSetup[lib/logger_setup.rb]
CommandExecutor --> CommandRunner
CommandRunner --> PdfBuilder
CommandRunner --> EbookBuilder
CommandRunner --> LatexToWikijs
CommandRunner --> QualityChecker
PdfBuilder --> BuildEbooks
EbookBuilder --> BuildEbooks
LatexToWikijs --> BuildEbooks
QualityChecker --> BuildEbooks
MetadataLoader --> BookDeployer
MetadataLoader --> EbookValidator
MetadataHandler --> SetupProject
MetadataHandler --> BuildEbooks
LoggerSetup --> BuildEbooks
Common Issues Found
-
Inconsistent Error Handling
- Different approaches to error handling across components
- Mix of custom error classes and generic exceptions
- Inconsistent use of error messages and logging
-
Path Management
- Hardcoded paths in multiple places
- Inconsistent path handling (Pathname vs String)
- Path resolution logic spread across components
-
Command Execution
- Multiple implementations of command existence checking
- Inconsistent use of system(), backticks, and Open3
- Limited sanitization of command inputs
-
Logging
- Inconsistent logging patterns
- Mix of puts and Logger usage
- Insufficient contextual information in log messages
-
Configuration Management
- Multiple approaches to configuration loading
- Inconsistent naming and access patterns
- Limited validation of configuration values
-
Testing Gaps
- Limited test coverage overall
- Difficult to test file system operations
- Tight coupling makes unit testing challenging
Next Audit Targets
- BookProcessing::Utilities::CommandRunner - Extends CommandExecutor, used throughout the system
- BookProcessing::MetadataHandler - Critical for project configuration
- BookProcessing::LoggerSetup - Establishes logging patterns
- BookProcessing::Builders::PdfBuilder - Core format generation component
Elixir Migration Considerations
-
Concurrency Model
- Replace Ruby threads with Elixir processes
- Use Task for parallel operations
- Leverage supervision for worker management
-
Error Handling
- Adopt "let it crash" philosophy where appropriate
- Use
{:ok, result} | {:error, reason}patterns - Implement proper supervision strategies
-
File System Operations
- Replace FileUtils with File/Path operations
- Consider agent-based file system abstraction
- Implement proper stream-based file processing
-
External Commands
- Replace Open3 with System.cmd/3 or Port
- Consider port-based communication for long-running processes
- Implement proper timeout handling
-
Configuration
- Use Application environment for configuration
- Implement proper runtime configuration
- Validate configuration at startup
Audit Completion Checklist
- Create audit templates
- Set up audit tracking
- Complete first component audit (CommandExecutor)
- Audit multiple core scripts (5 completed)
- Map full dependency relationships
- Complete core component audits
- Identify common patterns and inconsistencies
- Document initial Elixir migration considerations
- Analyze error handling patterns in depth
- Review logging practices across the codebase