0.03
A long-lived project that still receives updates
convert ruby code to better syntax automatically.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

synvert-core-ruby

logo

AwesomeCode Status for synvert-hq/synvert-core-ruby Build Status Gem Version

Synvert core provides a set of DSLs to rewrite ruby code. e.g.

Synvert::Rewriter.new 'factory_bot', 'convert_factory_girl_to_factory_bot' do
  description <<~EOS
    It converts FactoryGirl to FactoryBot

    ```ruby
    require 'factory_girl'
    require 'factory_girl_rails'
    ```

    =>

    ```ruby
    require 'factory_bot'
    require 'factory_bot_rails'
    ```

    ```ruby
    FactoryGirl.create(:user)
    FactoryGirl.build(:user)
    ```

    =>

    ```ruby
    FactoryBot.create(:user)
    FactoryBot.build(:user)
    ```
  EOS

  within_files Synvert::RAILS_TEST_FILES do
    find_node '.const[name=FactoryGirl]' do
      replace_with 'FactoryBot'
    end

    find_node ".send[receiver=nil][message=require][arguments.size=1][arguments.first='factory_girl']" do
      replace :arguments, with: "'factory_bot'"
    end

    with_node type: 'send', receiver: nil, message: 'require', arguments: { size: 1, first: "'factory_girl_rails'" } do
      replace :arguments, with: "'factory_bot_rails'"
    end
  end
end

Want to see more examples, check out synvert-snippets-ruby.

Want to use the CLI, check out synvert-ruby.

DSLs are as follows

Scopes:

Conditions:

Actions:

  • append - append the code to the bottom of current node body
  • prepend - prepend the code to the bottom of current node body
  • indent - indent code
  • insert - insert code
  • insert_after - insert the code next to the current node
  • insert_before - insert the code previous to the current node
  • replace - replace the code of specified child nodes
  • delete - delete the code in specified child nodes
  • remove - remove the whole code of current node
  • wrap - wrap the current node with prefix and suffix code
  • replace_with - replace the whole code of current node
  • warn - warn message
  • replace_erb_stmt_with_expr - replace erb stmt code to expr code
  • noop - no operation
  • group - group actions
  • add_action - add custom action

Others:

Attributes: