I am looking for a refactoring tool for rails application in Mac. After researching for whole week I am kind of surprised that there is no good tool available to refactor namespace/controller/model/view/routes in one go. I am bit new to Mac paradigm so may be I am missing something.
I can see few couple of gems developed for Rails which can do some rename/replace but still it requires “manual adjustments” after refactor.
To provide my requirement, here is standard Rails projects
# routes
map.namespace :admin do |admin|
admin.resources :items
end
match "/admin/items/:id/enable" => "admin/items#enable"
# model
/app/models/items.rb
class item < ActiveRecord::Base
end
# views
/app/views/admin/items/
/app/views/admin/items/index.html.erb
/app/views/admin/items/show.html.erb
/app/views/admin/items/new.html.erb
/app/views/admin/items/edit.html.erb
# controller
/app/controllers/admin/items_controller.rb
class Admin::ItemsController < ApplicationController
def index
#
end
def show
#
end
def enable
#
end
end
My requirement for this tool is very basic:
Refactoring: “item” to “product” – with case match
- Tool should rename any file contains “item” to “product”
- Tool should rename any folder contains “item” to “product”
- Tool should find and replace “item” and to “product” in all files in current or sub directory.
With above feature:
I can simply reactor whole project by:
> refactor "item" "product"
> refactor "Item" "Product"
> refactor "admin" "shop"
> refactor "Admin" "Shop"
Greatly appreciate if you can help me to provide link of any Mac tool or any script which can fulfill my above requirement.
Well I decided this sounded neat so I wrote a tool which seams to pull off what you want and I’ve decided to call it refacto.
Here’s your quick read-me:
Proper Usage is:
refacto findString changeString <file extensions> <options>File extensions are not optional. In order for any files to be renamed or refactored, you must list at least one file extension. Folders will be renamed by default, if you don’t want to rename them, use -nf.
Options:
-a : Ask for confirmation to refactor or rename each file/folder.
-nf : Do not rename folders or subfolders
-ci : Case Insenitive. Will change all versions of findString
Get the source code here: https://github.com/bpo217/refacto
A couple things to note:
Refacto changes ALL instances of findString in a file, not just a class name or anything like that.
Refacto will touch all subfolders and the files in those subfolders.
Since it’s a tool after you compile it just put it into /usr/local/bin and whatever else you need to do so you can just type refacto anywhere in terminal to run it. It will always work with the current working directory.
Hope this helps!