Renamespace
A command-line tool to help Ruby developers refactor class/module namespacing.
Contents
- Intro
- Installation
- Usage
- Example
- More usage info
- Development
- Pre-push hook
- Release
Intro
Renamespaces a Ruby source file:
- Moves the file
- Updates, to match the new location, the name of the class/module within the file, including its namespacing
- Updates usages of the class/module
- Updates the path to the file in all requires
- Moves the associated spec file
Class/module namespaces are derived from the paths provided.
If you change the number of namespaces, expect to have to run RuboCop autocorrect afterwards to clean up formatting.
The namespace replacing is not super smart yet, so it might get it wrong sometimes. If it does, see renamespace --help for some options that might help.
Installation
The executable is distributed as a gem. You can install it from RubyGems directly like so:
$ gem install renamespaceAnd then if you're using rbenv:
$ rbenv rehashUsage
$ renamespace SOURCE_FILE_PATH DESTINATION_FILE_PATHExample
With:
# lib/my_app/models/site.rb
module MyApp
module Models
class Site < BaseModel
end
end
endRun:
$ renamespace lib/my_app/models/site.rb lib/my_app/sites/model.rbResult:
# lib/my_app/sites/model.rb
module MyApp
module Sites
class Model < Models::BaseModel
end
end
endMore usage info
See:
$ renamespace --helpDevelopment
Pre-push hook
This hook runs style checks and tests.
To set up the pre-push hook:
$ echo -e "#\!/bin/bash\n\$(dirname \$0)/../../auto/pre-push-hook" > .git/hooks/pre-push
chmod +x .git/hooks/pre-pushRelease
To release a new version:
$ auto/release/update-version && auto/release/tag && auto/release/publishThis takes care of the whole process:
- Incrementing the version number (the patch number by default)
- Tagging & pushing commits
- Publishing the gem to RubyGems
- Creating a draft GitHub release
To increment the minor or major versions instead of the patch number, run auto/release/update-version with --minor or --major.