Remove external inflector shard dependency by vendoring the library into our project and improving it to fix known issues while maintaining 100% backward compatibility.
- Library:
phoffer/inflector.cr(v0.1.8) - Location: External shard in
shard.yml - Usage: Only 4 methods used from the library
# In src/amber_cli/core/word_transformer.cr:
Inflector.singularize(word) # Line 122
Inflector.pluralize(word) # Line 125
Inflector.classify(word) # Line 150
Inflector.foreign_key(word) # Line 157- "foot" β "foots" instead of "feet" (currently fixed with custom override)
- Potential other irregular plurals that need investigation
- Performance improvements using Crystal's built-in methods where possible
- 359 lines of comprehensive tests in
spec/core/word_transformer_spec.cr - Edge cases covered: empty strings, single chars, irregular plurals, acronyms
- Performance tests: 1000 iterations for built-in methods
- Custom conventions: Pattern overrides and fallbacks
- Clone
phoffer/inflector.crrepository - Analyze source code structure and implementation
- Identify the 4 methods we actually use
- Document current irregular plurals/singulars
- Create list of known incorrect transformations
- Compare with Rails ActiveSupport::Inflector for reference
- Research comprehensive lists of irregular English plurals
- Identify performance bottlenecks in current implementation
- Document Crystal built-in methods we can leverage
- Create
src/amber_cli/vendor/directory - Create
src/amber_cli/vendor/inflector/subdirectory - Add appropriate README and license attribution
- Copy only the required methods and dependencies
- Rename module to
AmberCLI::Vendor::Inflector - Remove unused methods to reduce code size
- Maintain original method signatures for compatibility
- Fix "foot" β "feet" (remove need for custom override)
- Add comprehensive irregular plurals list
- Fix any other documented incorrect transformations
- Add missing irregular singulars
- Use Crystal's
String#camelcaseinstead of custom implementation - Use Crystal's
String#underscoreinstead of custom implementation - Optimize regex patterns for better performance
- Add memoization for expensive operations if needed
- Create comprehensive IRREGULAR_PLURALS hash
- Create comprehensive IRREGULAR_SINGULARS hash
- Add common programming-related words (e.g., "schema" β "schemas")
- Include domain-specific terms relevant to web development
- Run existing test suite to ensure no regressions
- Create comparison tests between old and new implementations
- Document any intentional behavior changes (bug fixes)
- Ensure all 359 existing tests continue to pass
- Add tests for all irregular plurals/singulars
- Add performance benchmarks
- Test edge cases with new improvements
- Add tests for previously incorrect transformations
- Test with real Amber CLI workflows
- Verify generator output remains consistent
- Test template generation with new inflector
- Validate naming conventions work correctly
- Remove
inflectorfromshard.yml - Update require statements to use vendored version
- Update imports in
word_transformer.cr - Remove external dependency documentation
- Remove custom overrides that are now fixed in vendored version
- Simplify CUSTOM_PLURALS/CUSTOM_SINGULARS hashes
- Update comments explaining why custom overrides remain
- Update README with vendored library information
- Document improvements made over original
- Add attribution to original library authors
- Document any new irregular words added
-
git clone https://github.com/phoffer/inflector.cr - Document current implementation of
pluralizemethod - Document current implementation of
singularizemethod - Document current implementation of
classifymethod - Document current implementation of
foreign_keymethod - Create inventory of all irregular plurals in current library
- Identify performance bottlenecks and optimization opportunities
- Research comprehensive English irregular plurals (child/children, mouse/mice, etc.)
- Research programming-specific plurals (schema/schemas vs schemata)
- Create list of words that Rails ActiveSupport handles correctly
- Document any GitHub issues in original
phoffer/inflector.crrepo - Test original library against comprehensive word lists
- Create
src/amber_cli/vendor/inflector/ - Create
src/amber_cli/vendor/inflector/inflector.cr(main module) - Create
src/amber_cli/vendor/inflector/irregular_words.cr(word lists) - Create
src/amber_cli/vendor/inflector/README.md(attribution) - Create
src/amber_cli/vendor/inflector/LICENSE(copy original license)
- Copy
pluralizemethod and dependencies - Copy
singularizemethod and dependencies - Copy
classifymethod and dependencies - Copy
foreign_keymethod and dependencies - Rename module to
AmberCLI::Vendor::Inflector - Remove all unused methods and constants
- Maintain identical method signatures for drop-in replacement
- Add comprehensive irregular plurals list (appendix A of this plan)
- Add irregular singulars (reverse of plurals)
- Add programming-specific words:
- "schema" β "schemas" (not "schemata")
- "vertex" β "vertices" or "vertexes"
- "index" β "indexes" (not "indices" for programming)
- "matrix" β "matrices"
- "datum" β "data"
- Add web development specific words:
- "email" β "emails"
- "ajax" β "ajax calls"
- "api" β "apis"
- Fix "foot" β "feet" (currently returns "foots")
- Test and fix other known incorrect transformations
- Validate against comprehensive test cases
- Compare results with Rails ActiveSupport when possible
- Replace custom camel case with Crystal's
String#camelcase - Replace custom underscore with Crystal's
String#underscore - Optimize regex patterns for common cases
- Add benchmarking to measure improvements
- Run full existing test suite:
crystal spec - Ensure all 359 tests pass without modification
- Create before/after comparison tests for each method
- Document any intentional behavior changes (bug fixes)
- Add test for every word in irregular plurals list
- Add test for every word in irregular singulars list
- Add performance benchmarks comparing old vs new
- Add edge case tests for programming terminology
- Add tests for previously failing transformations
- Test
amber generate model User(pluralization) - Test
amber generate controller Posts(singularization) - Test scaffold generation with complex words
- Verify template generation still works correctly
- Test with custom naming conventions
- Remove
inflector:block fromshard.yml - Update
require "inflector"torequire "./vendor/inflector/inflector" - Update method calls from
Inflector.toAmberCLI::Vendor::Inflector. - Test compilation:
crystal build src/amber_cli.cr
- Remove custom overrides that are now fixed:
- Remove "foot" β "feet" from CUSTOM_PLURALS if fixed
- Clean up any other custom overrides that are redundant
- Update comments explaining remaining custom overrides
- Simplify word_transformer.cr if possible
- Update README.md with vendored library section
- Document improvements over original library
- Add attribution: "Based on phoffer/inflector.cr"
- Update CHANGELOG with migration details
- Add documentation for new irregular words added
- New implementation must be β₯ same speed as original
- Built-in Crystal methods should improve performance for camelcase/underscore
- Memory usage should be equal or better
- Benchmark against 1000+ word transformations
- 100% backward compatibility for all existing functionality
- All existing tests must pass without modification
- Same method signatures and return types
- Same error handling behavior
- Must fix "foot" β "feet" issue
- Must add at least 50 additional irregular plurals
- Must improve accuracy over original library
- Must maintain or improve performance
- Minimum 95% test coverage for vendored code
- All edge cases from original tests must pass
- New irregular words must have explicit tests
- Performance benchmarks must be included
IRREGULAR_PLURALS = {
# Body parts
"foot" => "feet",
"tooth" => "teeth",
"goose" => "geese",
# Animals
"mouse" => "mice",
"louse" => "lice",
"ox" => "oxen",
# People
"child" => "children",
"person" => "people",
"man" => "men",
"woman" => "women",
# Latin/Greek origins
"datum" => "data",
"genus" => "genera",
"corpus" => "corpora",
"opus" => "opera",
# Special cases
"sheep" => "sheep",
"deer" => "deer",
"fish" => "fish",
"series" => "series",
"species" => "species",
}PROGRAMMING_PLURALS = {
"schema" => "schemas", # Not "schemata" in programming
"index" => "indexes", # Not "indices" in programming
"vertex" => "vertices",
"matrix" => "matrices",
"regex" => "regexes",
"ajax" => "ajax",
"api" => "apis",
}- External
inflectordependency removed fromshard.yml - All tests pass:
crystal specreturns 0 failures - CLI compiles without errors:
crystal build src/amber_cli.cr - Performance equal or better than original
- At least 5 previously incorrect words now fixed
- Comprehensive test coverage for all new irregular words
- Test Coverage: >95% for vendored inflector code
- Performance: β₯100% of original speed
- Accuracy: β₯99% correct on standard English test cases
- Maintainability: Well-documented, clear code structure
- Compatibility: 100% backward compatible
- Phase 1 (Research): 4-6 hours
- Phase 2 (Setup): 2-3 hours
- Phase 3 (Improve): 6-8 hours
- Phase 4 (Testing): 4-6 hours
- Phase 5 (Migration): 2-3 hours
Total: ~18-26 hours of focused development time
-
Breaking Changes
- Risk: Vendored version behaves differently
- Solution: Comprehensive comparison testing before migration
-
Performance Regression
- Risk: New implementation slower than original
- Solution: Benchmark at each step, optimize hot paths
-
Missing Edge Cases
- Risk: Original library handles cases we missed
- Solution: Extract complete test suite from original library
-
Maintenance Burden
- Risk: Now responsible for maintaining inflector code
- Solution: Well-documented, simple implementation with comprehensive tests
This plan ensures a safe, systematic migration that improves functionality while maintaining complete backward compatibility.