Skip to content

Auto corrected by following Format Ruby Code #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/helpers/parse_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
with_configurations(number_of_workers: 1) do
tables = {}
within_file 'db/schema.rb' do
within_node node_type: 'call_node', name: 'create_table' do
within_node node_type: 'call_node', name: 'create_table' do
table_name = node.arguments.arguments.first.to_value
tables[table_name] = { columns: [], indices: [] }
with_node node_type: 'call_node', receiver: 't', message: { not: 'index' } do
Expand Down
5 changes: 4 additions & 1 deletion lib/helpers/set_rails_load_defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
within_file 'config/application.rb' do
with_node node_type: 'class_node', constant_path: 'Application' do
exists = false
with_node node_type: 'call_node', receiver: 'config', name: 'load_defaults', arguments: { arguments: { length: 1 } } do
with_node node_type: 'call_node',
receiver: 'config',
name: 'load_defaults',
arguments: { arguments: { length: 1 } } do
exists = true
replace_with "config.load_defaults #{rails_version}"
end
Expand Down
16 changes: 14 additions & 2 deletions lib/rails/convert_after_commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@
with_node node_type: 'call_node',
receiver: nil,
name: 'after_commit',
arguments: { node_type: 'arguments_node', arguments: { size: 2, '1': { node_type: 'keyword_hash_node', on_value: { in: %i[create update destroy] } } } } do
arguments: {
node_type: 'arguments_node',
arguments: {
size: 2,
'1': { node_type: 'keyword_hash_node', on_value: { in: %i[create update destroy] } }
}
} do
group do
replace :name, with: 'after_{{arguments.arguments.-1.on_value.to_value}}_commit'
delete 'arguments.arguments.-1.on_element', and_comma: true
Expand All @@ -60,7 +66,13 @@
with_node node_type: 'call_node',
receiver: nil,
message: 'after_commit',
arguments: { node_type: 'arguments_node', arguments: { size: 2, '1': { node_type: 'keyword_hash_node', on_value: { node_type: 'array_node' } } } } do
arguments: {
node_type: 'arguments_node',
arguments: {
size: 2,
'1': { node_type: 'keyword_hash_node', on_value: { node_type: 'array_node' } }
}
} do
group do
if node.arguments.arguments[1].on_value.elements.size == 1
replace :message, with: 'after_{{arguments.arguments.-1.on_value.elements.0.to_value}}_commit'
Expand Down
8 changes: 2 additions & 6 deletions lib/rails/convert_configs_3_0_to_3_1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,12 @@ def down

within_file 'config/environments/test.rb' do
# prepend config.static_cache_control = "public, max-age=3600"
unless_exist_node node_type: 'call_node',
receiver: 'config',
name: 'static_cache_control=' do
unless_exist_node node_type: 'call_node', receiver: 'config', name: 'static_cache_control=' do
prepend 'config.static_cache_control = "public, max-age=3600"'
end

# prepend config.serve_static_assets = true
unless_exist_node node_type: 'call_node',
receiver: 'config',
name: 'serve_static_assets=' do
unless_exist_node node_type: 'call_node', receiver: 'config', name: 'serve_static_assets=' do
prepend 'config.serve_static_assets = true'
end
end
Expand Down
26 changes: 22 additions & 4 deletions lib/rails/convert_configs_3_2_to_4_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@
end

# remove config.middleware.xxx(..., ActionDispatch::BestStandardsSupport)
with_node node_type: 'call_node', arguments: { node_type: 'arguments_node', arguments: { includes: 'ActionDispatch::BestStandardsSupport' } } do
with_node node_type: 'call_node',
arguments: {
node_type: 'arguments_node',
arguments: { includes: 'ActionDispatch::BestStandardsSupport' }
} do
remove
end

Expand Down Expand Up @@ -153,9 +157,23 @@
receiver: 'ActiveSupport',
name: 'on_load',
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: :active_record } },
block: { node_type: 'block_node', body: { node_type: 'statements_node', body: { size: 1, first: {
node_type: 'call_node', receiver: 'self', name: 'include_root_in_json=', arguments: { node_type: 'arguments_node', arguments: { size: 1, first: false } }
} } } } do
block: {
node_type: 'block_node',
body: {
node_type: 'statements_node',
body: {
size: 1,
first: {
node_type: 'call_node',
receiver: 'self',
name: 'include_root_in_json=',
arguments: {
node_type: 'arguments_node', arguments: { size: 1, first: false }
}
}
}
}
} do
remove
end
end
Expand Down
5 changes: 4 additions & 1 deletion lib/rails/convert_configs_4_2_to_5_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@
name: 'middleware'
},
name: 'use',
arguments: { node_type: 'arguments_node', arguments: { size: { gt: 0 }, first: { node_type: 'string_node' } } } do
arguments: {
node_type: 'arguments_node',
arguments: { size: { gt: 0 }, first: { node_type: 'string_node' } }
} do
replace 'arguments.arguments.first', with: "{{arguments.arguments.first.to_value}}"
end
end
Expand Down
9 changes: 7 additions & 2 deletions lib/rails/convert_dynamic_finders_for_rails_3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@

call_helper 'rails/parse'
rails_tables = load_data :rails_tables
table_columns = rails_tables.present? ? rails_tables.values.flat_map { |value| value[:columns] }.map { |column| column[:name] } + ['id'] : []
table_columns =
rails_tables.present? ? rails_tables.values.flat_map { |value|
value[:columns]
}
.map { |column| column[:name] } + ['id'] : []

helper_method :dynamic_finder_to_hash do |prefix|
fields = node.name.to_s[prefix.length..-1].split('_and_')
return nil if (fields - table_columns).present?

if fields.length == node.arguments.arguments.length && :hash_node != node.arguments.arguments.first.type
fields.length.times.map { |i| fields[i] + ': ' + node.arguments.arguments[i].to_source }.join(', ')
fields.length.times.map { |i| fields[i] + ': ' + node.arguments.arguments[i].to_source }
.join(', ')
else
'{{arguments}}'
end
Expand Down
9 changes: 7 additions & 2 deletions lib/rails/convert_dynamic_finders_for_rails_4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@

call_helper 'rails/parse'
rails_tables = load_data :rails_tables
table_columns = rails_tables.present? ? rails_tables.values.flat_map { |value| value[:columns] }.map { |column| column[:name] } + ['id'] : []
table_columns =
rails_tables.present? ? rails_tables.values.flat_map { |value|
value[:columns]
}
.map { |column| column[:name] } + ['id'] : []

helper_method :dynamic_finder_to_hash do |prefix|
fields = node.name.to_s[prefix.length..-1].split('_and_')
return nil if (fields - table_columns).present?

if fields.length == node.arguments.arguments.length && :hash_node != node.arguments.arguments.first.type
fields.length.times.map { |i| fields[i] + ': ' + node.arguments.arguments[i].to_source }.join(', ')
fields.length.times.map { |i| fields[i] + ': ' + node.arguments.arguments[i].to_source }
.join(', ')
else
'{{arguments}}'
end
Expand Down
21 changes: 18 additions & 3 deletions lib/rails/convert_head_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
with_node node_type: 'call_node',
receiver: nil,
name: 'render',
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: { node_type: 'keyword_hash_node', nothing_value: true } } } do
arguments: {
node_type: 'arguments_node',
arguments: { size: 1, first: { node_type: 'keyword_hash_node', nothing_value: true } }
} do
group do
replace :message, with: 'head'
if node.arguments.arguments.first.status_value.nil?
Expand All @@ -53,7 +56,13 @@
with_node node_type: 'call_node',
receiver: nil,
name: 'head',
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: { node_type: 'keyword_hash_node', location_value: { not: nil } } } } do
arguments: {
node_type: 'arguments_node',
arguments: {
size: 1,
first: { node_type: 'keyword_hash_node', location_value: { not: nil } }
}
} do
replace 'arguments.arguments.0', with: ':ok, {{arguments.arguments.0.to_source}}'
end

Expand All @@ -63,7 +72,13 @@
with_node node_type: 'call_node',
receiver: nil,
name: 'head',
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: { node_type: 'keyword_hash_node', status_value: { not: nil } } } } do
arguments: {
node_type: 'arguments_node',
arguments: {
size: 1,
first: { node_type: 'keyword_hash_node', status_value: { not: nil } }
}
} do
replace 'arguments.arguments.0', with: '{{arguments.arguments.0.status_source}}'
end
end
Expand Down
23 changes: 18 additions & 5 deletions lib/rails/convert_mailers_2_3_to_3_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ def signup_notification(recipient)
class_name = node.name
within_node node_type: 'def_node' do
args = {}
with_node node_type: 'call_node', receiver: nil, name: 'recipients', arguments: { node_type: 'arguments_node', arguments: { size: 1 } } do
with_node node_type: 'call_node',
receiver: nil,
name: 'recipients',
arguments: { node_type: 'arguments_node', arguments: { size: 1 } } do
args[:to] = node.arguments.arguments.first.to_source
remove
end
Expand All @@ -97,13 +100,20 @@ def signup_notification(recipient)
with_node node_type: 'call_node',
receiver: nil,
name: 'body',
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: { node_type: 'keyword_hash_node' } } } do
replace_with node.arguments.arguments.first.elements.map { |element| "@#{element.key.to_value} = #{element.value.to_source}" }.join("\n")
arguments: {
node_type: 'arguments_node',
arguments: { size: 1, first: { node_type: 'keyword_hash_node' } }
} do
replace_with node.arguments.arguments.first.elements.map { |element|
"@#{element.key.to_value} = #{element.value.to_source}"
}
.join("\n")
end
if args.size > 0
mailer_methods[class_name] ||= []
mailer_methods[class_name] << node.name
args_str = args.map { |key, value| ":#{key} => #{value}" }.join(', ')
args_str = args.map { |key, value| ":#{key} => #{value}" }
.join(', ')
append "mail(#{args_str})"
end
end
Expand Down Expand Up @@ -134,7 +144,10 @@ def signup_notification(recipient)
# Notifier.deliver(message)
# =>
# message.deliver
with_node node_type: 'call_node', receiver: { not: nil }, name: 'deliver', arguments: { node_type: 'arguments_node', arguments: { size: 1 } } do
with_node node_type: 'call_node',
receiver: { not: nil },
name: 'deliver',
arguments: { node_type: 'arguments_node', arguments: { size: 1 } } do
if mailer_methods[node.receiver.name]
replace_with '{{arguments}}.{{message}}'
end
Expand Down
11 changes: 5 additions & 6 deletions lib/rails/convert_model_lambda_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class Post < ActiveRecord::Base
}
} do
if node.arguments.arguments.last.block.parameters
replace 'arguments.arguments.last', with: '->({{arguments.arguments.last.block.parameters.parameters}}) { {{arguments.arguments.last.block.body}} }'
replace 'arguments.arguments.last',
with: '->({{arguments.arguments.last.block.parameters.parameters}}) { {{arguments.arguments.last.block.body}} }'
else
replace 'arguments.arguments.last', with: '-> { {{arguments.arguments.last.block.body}} }'
end
Expand All @@ -87,7 +88,8 @@ class Post < ActiveRecord::Base
}
} do
if node.arguments.arguments.last.block.parameters
replace 'arguments.arguments.last', with: '->({{arguments.arguments.last.block.parameters.parameters}}) { {{arguments.arguments.last.block.body}} }'
replace 'arguments.arguments.last',
with: '->({{arguments.arguments.last.block.parameters.parameters}}) { {{arguments.arguments.last.block.body}} }'
else
replace 'arguments.arguments.last', with: '-> { {{arguments.arguments.last.block.body}} }'
end
Expand All @@ -102,10 +104,7 @@ class Post < ActiveRecord::Base
end

# default_scope { order("updated_at DESC") } => default_scope -> { order("updated_at DESC") }
with_node node_type: 'call_node',
receiver: nil,
name: 'default_scope',
block: { node_type: 'block_node' } do
with_node node_type: 'call_node', receiver: nil, name: 'default_scope', block: { node_type: 'block_node' } do
replace_with 'default_scope -> { {{block.body.body}} }'
end
end
Expand Down
Loading
Loading