Coder Social home page Coder Social logo

refactor.ex's Introduction

๐Ÿ”ฎ Refactor.ex

A commandline utility to make refactoring projects easier. Currently the primary use-case is renaming constants/models/modules/etc.

For example

./refactor --from Tag --to Category --file ./example.ex

Would replace these strings in example.ex:

Tag  -> Category
Tags -> Categories 
tag  -> category
tags -> categories

Features

  • Rename models/constants
    • Find/replace strings in a single file
    • Auto generate varations of pattern (capitalize, lowercase, pluralization)
    • Support glob patterns or multiple files (--files one.ex,two.ex)
    • Async: process multiple files at once
    • Print # of strings replaced
    • Verbose mode to list all individual changes + line number
  • Rename filenames too (optionally)
  • Rename functions feature

Example

Renaming:

The utility generates all variations of "from" and "to" including Capitalization, lowercase, and pluralization to make sure each gets replaced. For example:

  iex> Refactor.patterns("Comment", "Category")
  [
    ["Comments", "Categories"],
    ["Comment",  "Category"  ],
    ["comments", "categories"],
    ["comment",  "category"  ],
  ]

The above happens automatically when you call rename on a file:

  iex> Refactor.rename("Comment", "Category", "./sample_test.ex")
  Done

Installation

git clone https://github.com/dmix/refactor.ex
cd refactor.ex
make

Use program in the current directory:

./refactor --from A --to B --file ./sample_test.ex

Or install to /usr/local/bin/refactor

make install

Usage

Required arguments:

    --from, -f = Name of existing model/contant to rename
    --to,   -t = Name of new constant to replace it with
    --file, -p = Filepath to replace strings in

For example:

    ./refactor --from Comment --to Category --file ./sample_test.ex

    ./refactor -f Comment -t Category -p ./sample_test.ex

License

GNU v3

By Daniel P. McGrady - https://dmix.ca

refactor.ex's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

bglusman

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.