0.0
Low commit activity in last 3 years
No release in over a year
A command-line tool to help Ruby developers refactor class/module namespacing
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.3.2
~> 3.1.0
~> 3.0.0
 Project Readme

Renamespace

CI status Gem Version

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 renamespace

And then if you're using rbenv:

$ rbenv rehash

Usage

$ renamespace SOURCE_FILE_PATH DESTINATION_FILE_PATH

Example

With:

# lib/my_app/models/site.rb

module MyApp
  module Models
    class Site < BaseModel
    end
  end
end

Run:

$ renamespace lib/my_app/models/site.rb lib/my_app/sites/model.rb

Result:

# lib/my_app/sites/model.rb

module MyApp
  module Sites
    class Model < Models::BaseModel
    end
  end
end

More usage info

See:

$ renamespace --help

Development

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-push

Release

To release a new version:

$ 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.