Created
July 16, 2016 12:14
-
-
Save eagletmt/abe1755ae570293ce161dcba5ba3b45b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: synvert --load rails50_ac_test_case.rb --run rails/rails50_ac_test_case | |
Synvert::Rewriter.new('rails', 'rails50_ac_test_case') do | |
helper_method :rewrite_with_new_syntax do | |
if node.arguments.size == 2 && node.arguments[1].type == :hash | |
params = node.arguments[1].to_source | |
if params[0] != '{' | |
params = "{ #{params} }" | |
end | |
replace_with("#{node.message} #{node.arguments[0].to_source}, params: #{params}") | |
elsif node.arguments.size == 2 && node.arguments[1].type == :send && node.arguments[1].receiver == nil && node.arguments[1].arguments.empty? | |
replace_with("#{node.message} #{node.arguments[0].to_source}, params: #{node.arguments[1].to_source}") | |
end | |
end | |
within_files 'spec/**/*.rb' do | |
%w[get post put delete].each do |meth| | |
with_node(type: 'send', receiver: nil, message: meth) do | |
rewrite_with_new_syntax | |
end | |
end | |
with_node(type: 'send', receiver: nil, message: 'xhr') do | |
if node.arguments[0].type == :sym | |
code = "#{node.arguments[0].children[0].to_s} #{node.arguments[1].to_source}, xhr: true" | |
if node.arguments.size == 2 | |
replace_with(code) | |
elsif node.arguments.size == 3 | |
params = node.arguments[2].to_source | |
if params[0] != '{' | |
params = "{ #{params} }" | |
end | |
replace_with("#{code}, params: #{params}") | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment