Skip to content

lvela/cambiar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cambiar

It's easy to accidently change something with find/replace that you didn't mean to change. Cambiar makes find/replace safer by replacing only certain types using the Ruby AST.

Installation

Add this line to your application's Gemfile:

gem 'cambiar'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cambiar

Usage

Usage: cambiar [-ic] "s/<from>/<to>/" [file ...]
    -i, --on_ident                   Substitute identifers
    -c, --on_const                   Substitute constants

Examples

Change identifiers

cambiar -i "s/reader/fast_reader/" test.rb

before

class Reader
  READER = 'reader'

  def my_reader
    puts "Reader reader"
  end 
end

after

class Reader
  READER = 'reader'

  def my_fast_reader
    puts "Reader reader"
  end 
end

Change constants

cambiar -c "s/READER/FAST_READER/" test.rb

before

class Reader
  READER = 'reader'

  def my_reader
    puts "READER Reader reader"
  end
end

after

class Reader
  FAST_READER = 'reader'

  def my_reader
    puts "READER Reader reader"
  end 
end

Contributing

  1. Fork it ( http://github.com//cambiar/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Ruby Substitution using the AST

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages