https://github.com/zimbix/renamespace
A command-line tool to help Ruby developers refactor class/module namespacing.
https://github.com/zimbix/renamespace
refactoring ruby tool
Last synced: about 1 year ago
JSON representation
A command-line tool to help Ruby developers refactor class/module namespacing.
- Host: GitHub
- URL: https://github.com/zimbix/renamespace
- Owner: ZimbiX
- License: gpl-3.0
- Created: 2021-04-23T15:57:59.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-21T04:43:52.000Z (over 3 years ago)
- Last Synced: 2024-05-01T14:19:27.338Z (about 2 years ago)
- Topics: refactoring, ruby, tool
- Language: Ruby
- Homepage:
- Size: 129 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Renamespace
[](https://github.com/ZimbiX/renamespace/actions/workflows/main.yml) [](https://rubygems.org/gems/renamespace)
A command-line tool to help Ruby developers refactor class/module namespacing.
## Contents
- [Intro](#intro)
- [Installation](#installation)
- [Usage](#usage)
- [Example](#example)
- [More usage info](#more-usage-info)
- [Development](#development)
- [Pre-push hook](#pre-push-hook)
- [Release](#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:
```bash
$ gem install renamespace
```
And then if you're using rbenv:
```bash
$ rbenv rehash
```
## Usage
```bash
$ renamespace SOURCE_FILE_PATH DESTINATION_FILE_PATH
```
## Example
With:
```ruby
# lib/my_app/models/site.rb
module MyApp
module Models
class Site < BaseModel
end
end
end
```
Run:
```bash
$ renamespace lib/my_app/models/site.rb lib/my_app/sites/model.rb
```
Result:
```ruby
# lib/my_app/sites/model.rb
module MyApp
module Sites
class Model < Models::BaseModel
end
end
end
```
## More usage info
See:
```bash
$ renamespace --help
```
## Development
### Pre-push hook
This hook runs style checks and tests.
To set up the pre-push hook:
```bash
$ echo -e "#\!/bin/bash\n\$(dirname \$0)/../../auto/pre-push-hook" > .git/hooks/pre-push
chmod +x .git/hooks/pre-push
```
### Release
To release a new version:
```bash
$ auto/release/update-version && auto/release/tag && auto/release/publish
```
This 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`.