Skip to content

Commit 7721fe8

Browse files
author
Awesome Code
committed
Auto corrected by following Format Ruby Code
1 parent 006e26a commit 7721fe8

37 files changed

+538
-198
lines changed

lib/helpers/parse_rails.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Set number_of_workers to 1 to skip parallel.
1111
with_configurations(number_of_workers: 1) do
1212
within_file 'db/schema.rb' do
13-
within_node node_type: 'call_node', name: 'create_table' do
13+
within_node node_type: 'call_node', name: 'create_table' do
1414
table_name = node.arguments.arguments.first.to_value
1515
with_node node_type: 'call_node', receiver: 't', message: { not: 'index' } do
1616
column_name = node.arguments.arguments.first.to_value
@@ -92,7 +92,7 @@ def find_or_create_table_definition(table_name)
9292
end
9393

9494
def find_table_definition_by_table_name(table_name)
95-
@table_definitions.find { |table| table.name == table_name }
95+
@table_definitions.find { |table| table.name == table_name }
9696
end
9797

9898
def to_h
@@ -118,7 +118,7 @@ def add_index(name, columns)
118118
end
119119

120120
def find_index_definition_by_column_names(column_names)
121-
@indices.find { |index_definition| index_definition.columns == column_names }
121+
@indices.find { |index_definition| index_definition.columns == column_names }
122122
end
123123

124124
def get_column_names
@@ -175,7 +175,7 @@ def add_model_association(model_name, association_name, association_type, **asso
175175
end
176176

177177
def find_or_create_model_definition(model_name)
178-
model_definition = @model_definitions.find { |model_definition| model_definition.name == model_name }
178+
model_definition = @model_definitions.find { |model_definition| model_definition.name == model_name }
179179
return model_definition if model_definition
180180

181181
model_definition = ModelDefinition.new(name: model_name)

lib/helpers/parse_ruby.rb

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,22 @@
4444
end
4545

4646
add_callback :call_node, at: 'start' do |node|
47-
if node.receiver.nil? && node.name == :include && definitions.current_node_type == "class" && !node.arguments.nil? && %i[constant_read_node constant_path_node].include?(node.arguments.arguments.first.type)
47+
if node.receiver.nil? && node.name == :include && definitions.current_node_type == "class" && !node.arguments.nil? && %i[
48+
constant_read_node constant_path_node
49+
].include?(node.arguments.arguments.first.type)
50+
4851
definitions.add_include_module(node.arguments.arguments.first.to_source)
4952
end
50-
if node.receiver.nil? && node.name == :prepend && definitions.current_node_type == "class" && !node.arguments.nil? && %i[constant_read_node constant_path_node].include?(node.arguments.arguments.first.type)
53+
if node.receiver.nil? && node.name == :prepend && definitions.current_node_type == "class" && !node.arguments.nil? && %i[
54+
constant_read_node constant_path_node
55+
].include?(node.arguments.arguments.first.type)
56+
5157
definitions.add_prepend_module(node.arguments.arguments.first.to_source)
5258
end
53-
if node.receiver.nil? && node.name == :extend && definitions.current_node_type == "class" && !node.arguments.nil? && %i[constant_read_node constant_path_node].include?(node.arguments.arguments.first.type)
59+
if node.receiver.nil? && node.name == :extend && definitions.current_node_type == "class" && !node.arguments.nil? && %i[
60+
constant_read_node constant_path_node
61+
].include?(node.arguments.arguments.first.type)
62+
5463
definitions.add_extend_module(node.arguments.arguments.first.to_source)
5564
end
5665
end
@@ -182,7 +191,7 @@ def find_classes_by_ancestor(superclass)
182191
end
183192

184193
def find_method_by_name(name)
185-
methods.find { |method_definition| method_definition.name == name }
194+
methods.find { |method_definition| method_definition.name == name }
186195
end
187196

188197
def full_name
@@ -259,7 +268,12 @@ def initialize
259268
end
260269

261270
def to_h
262-
{ modules: @modules.map(&:to_h), classes: @classes.map(&:to_h), constants: @constants, methods: @methods.map(&:to_h) }
271+
{
272+
modules: @modules.map(&:to_h),
273+
classes: @classes.map(&:to_h),
274+
constants: @constants,
275+
methods: @methods.map(&:to_h)
276+
}
263277
end
264278
end
265279

@@ -286,14 +300,24 @@ def to_h
286300
methods: @methods.map(&:to_h),
287301
static_methods: @static_methods.map(&:to_h),
288302
constants: @constants,
289-
singleton: @singleton &.to_h,
303+
singleton: @singleton&.to_h,
290304
ancestors: @ancestors
291305
}
292306
end
293307
end
294308

295309
class ClassDefinition < BaseDefinition
296-
attr_reader :parent, :name, :superclass, :modules, :classes, :methods, :static_methods, :constants, :include_modules, :prepend_modules, :extend_modules
310+
attr_reader :parent,
311+
:name,
312+
:superclass,
313+
:modules,
314+
:classes,
315+
:methods,
316+
:static_methods,
317+
:constants,
318+
:include_modules,
319+
:prepend_modules,
320+
:extend_modules
297321
attr_accessor :singleton, :ancestors
298322

299323
def initialize(parent:, name:, superclass:)
@@ -360,11 +384,13 @@ def initialize(parent:, name:)
360384

361385
def call_method?(method_name)
362386
local_calls.include?(method_name) ||
363-
local_calls.any? { |local_call_method_name| parent.find_method_by_name(local_call_method_name)&.call_method?(method_name) }
387+
local_calls.any? { |local_call_method_name|
388+
parent.find_method_by_name(local_call_method_name)&.call_method?(method_name)
389+
}
364390
end
365391

366392
def call_any_method?(method_names)
367-
method_names.any? { |method_name| call_method?(method_name) }
393+
method_names.any? { |method_name| call_method?(method_name) }
368394
end
369395

370396
def to_h

lib/helpers/set_rails_load_defaults.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
within_file 'config/application.rb' do
99
with_node node_type: 'class_node', constant_path: 'Application' do
1010
exists = false
11-
with_node node_type: 'call_node', receiver: 'config', name: 'load_defaults', arguments: { arguments: { length: 1 } } do
11+
with_node node_type: 'call_node',
12+
receiver: 'config',
13+
name: 'load_defaults',
14+
arguments: { arguments: { length: 1 } } do
1215
exists = true
1316
replace_with "config.load_defaults #{rails_version}"
1417
end

lib/rails/convert_after_commit.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@
4141
with_node node_type: 'call_node',
4242
receiver: nil,
4343
name: 'after_commit',
44-
arguments: { node_type: 'arguments_node', arguments: { size: 2, '1': { node_type: 'keyword_hash_node', on_value: { in: %i[create update destroy] } } } } do
44+
arguments: {
45+
node_type: 'arguments_node',
46+
arguments: {
47+
size: 2,
48+
'1': { node_type: 'keyword_hash_node', on_value: { in: %i[create update destroy] } }
49+
}
50+
} do
4551
group do
4652
replace :name, with: 'after_{{arguments.arguments.-1.on_value.to_value}}_commit'
4753
delete 'arguments.arguments.-1.on_element', and_comma: true
@@ -60,7 +66,13 @@
6066
with_node node_type: 'call_node',
6167
receiver: nil,
6268
message: 'after_commit',
63-
arguments: { node_type: 'arguments_node', arguments: { size: 2, '1': { node_type: 'keyword_hash_node', on_value: { node_type: 'array_node' } } } } do
69+
arguments: {
70+
node_type: 'arguments_node',
71+
arguments: {
72+
size: 2,
73+
'1': { node_type: 'keyword_hash_node', on_value: { node_type: 'array_node' } }
74+
}
75+
} do
6476
group do
6577
if node.arguments.arguments[1].on_value.elements.size == 1
6678
replace :message, with: 'after_{{arguments.arguments.-1.on_value.elements.0.to_value}}_commit'

lib/rails/convert_configs_3_0_to_3_1.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,12 @@ def down
173173

174174
within_file 'config/environments/test.rb' do
175175
# prepend config.static_cache_control = "public, max-age=3600"
176-
unless_exist_node node_type: 'call_node',
177-
receiver: 'config',
178-
name: 'static_cache_control=' do
176+
unless_exist_node node_type: 'call_node', receiver: 'config', name: 'static_cache_control=' do
179177
prepend 'config.static_cache_control = "public, max-age=3600"'
180178
end
181179

182180
# prepend config.serve_static_assets = true
183-
unless_exist_node node_type: 'call_node',
184-
receiver: 'config',
185-
name: 'serve_static_assets=' do
181+
unless_exist_node node_type: 'call_node', receiver: 'config', name: 'serve_static_assets=' do
186182
prepend 'config.serve_static_assets = true'
187183
end
188184
end

lib/rails/convert_configs_3_2_to_4_0.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@
102102
end
103103

104104
# remove config.middleware.xxx(..., ActionDispatch::BestStandardsSupport)
105-
with_node node_type: 'call_node', arguments: { node_type: 'arguments_node', arguments: { includes: 'ActionDispatch::BestStandardsSupport' } } do
105+
with_node node_type: 'call_node',
106+
arguments: {
107+
node_type: 'arguments_node',
108+
arguments: { includes: 'ActionDispatch::BestStandardsSupport' }
109+
} do
106110
remove
107111
end
108112

@@ -153,9 +157,23 @@
153157
receiver: 'ActiveSupport',
154158
name: 'on_load',
155159
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: :active_record } },
156-
block: { node_type: 'block_node', body: { node_type: 'statements_node', body: { size: 1, first: {
157-
node_type: 'call_node', receiver: 'self', name: 'include_root_in_json=', arguments: { node_type: 'arguments_node', arguments: { size: 1, first: false } }
158-
} } } } do
160+
block: {
161+
node_type: 'block_node',
162+
body: {
163+
node_type: 'statements_node',
164+
body: {
165+
size: 1,
166+
first: {
167+
node_type: 'call_node',
168+
receiver: 'self',
169+
name: 'include_root_in_json=',
170+
arguments: {
171+
node_type: 'arguments_node', arguments: { size: 1, first: false }
172+
}
173+
}
174+
}
175+
}
176+
} do
159177
remove
160178
end
161179
end

lib/rails/convert_configs_4_2_to_5_0.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@
5555
name: 'middleware'
5656
},
5757
name: 'use',
58-
arguments: { node_type: 'arguments_node', arguments: { size: { gt: 0 }, first: { node_type: 'string_node' } } } do
58+
arguments: {
59+
node_type: 'arguments_node',
60+
arguments: { size: { gt: 0 }, first: { node_type: 'string_node' } }
61+
} do
5962
replace 'arguments.arguments.first', with: "{{arguments.arguments.first.to_value}}"
6063
end
6164
end

lib/rails/convert_dynamic_finders_for_rails_3.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@
2828
EOS
2929

3030
definitions = call_helper 'rails/parse'
31-
table_columns = definitions.table_definitions.flat_map { |table_definition| table_definition.get_column_names }.uniq + ['id']
31+
table_columns = definitions.table_definitions.flat_map { |table_definition|
32+
table_definition.get_column_names
33+
}
34+
.uniq + ['id']
3235

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

3740
if fields.length == node.arguments.arguments.length && :hash_node != node.arguments.arguments.first.type
38-
fields.length.times.map { |i| fields[i] + ': ' + node.arguments.arguments[i].to_source }.join(', ')
41+
fields.length.times.map { |i| fields[i] + ': ' + node.arguments.arguments[i].to_source }
42+
.join(', ')
3943
else
4044
'{{arguments}}'
4145
end

lib/rails/convert_dynamic_finders_for_rails_4.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@
2020
EOS
2121

2222
definitions = call_helper 'rails/parse'
23-
table_columns = definitions.table_definitions.flat_map { |table_definition| table_definition.get_column_names }.uniq + ['id']
23+
table_columns = definitions.table_definitions.flat_map { |table_definition|
24+
table_definition.get_column_names
25+
}
26+
.uniq + ['id']
2427

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

2932
if fields.length == node.arguments.arguments.length && :hash_node != node.arguments.arguments.first.type
30-
fields.length.times.map { |i| fields[i] + ': ' + node.arguments.arguments[i].to_source }.join(', ')
33+
fields.length.times.map { |i| fields[i] + ': ' + node.arguments.arguments[i].to_source }
34+
.join(', ')
3135
else
3236
'{{arguments}}'
3337
end

lib/rails/convert_head_response.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
with_node node_type: 'call_node',
3737
receiver: nil,
3838
name: 'render',
39-
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: { node_type: 'keyword_hash_node', nothing_value: true } } } do
39+
arguments: {
40+
node_type: 'arguments_node',
41+
arguments: { size: 1, first: { node_type: 'keyword_hash_node', nothing_value: true } }
42+
} do
4043
group do
4144
replace :message, with: 'head'
4245
if node.arguments.arguments.first.status_value.nil?
@@ -53,7 +56,13 @@
5356
with_node node_type: 'call_node',
5457
receiver: nil,
5558
name: 'head',
56-
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: { node_type: 'keyword_hash_node', location_value: { not: nil } } } } do
59+
arguments: {
60+
node_type: 'arguments_node',
61+
arguments: {
62+
size: 1,
63+
first: { node_type: 'keyword_hash_node', location_value: { not: nil } }
64+
}
65+
} do
5766
replace 'arguments.arguments.0', with: ':ok, {{arguments.arguments.0.to_source}}'
5867
end
5968

@@ -63,7 +72,13 @@
6372
with_node node_type: 'call_node',
6473
receiver: nil,
6574
name: 'head',
66-
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: { node_type: 'keyword_hash_node', status_value: { not: nil } } } } do
75+
arguments: {
76+
node_type: 'arguments_node',
77+
arguments: {
78+
size: 1,
79+
first: { node_type: 'keyword_hash_node', status_value: { not: nil } }
80+
}
81+
} do
6782
replace 'arguments.arguments.0', with: '{{arguments.arguments.0.status_source}}'
6883
end
6984
end

lib/rails/convert_mailers_2_3_to_3_0.rb

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ def signup_notification(recipient)
7979
class_name = node.name
8080
within_node node_type: 'def_node' do
8181
args = {}
82-
with_node node_type: 'call_node', receiver: nil, name: 'recipients', arguments: { node_type: 'arguments_node', arguments: { size: 1 } } do
82+
with_node node_type: 'call_node',
83+
receiver: nil,
84+
name: 'recipients',
85+
arguments: { node_type: 'arguments_node', arguments: { size: 1 } } do
8386
args[:to] = node.arguments.arguments.first.to_source
8487
remove
8588
end
@@ -97,13 +100,20 @@ def signup_notification(recipient)
97100
with_node node_type: 'call_node',
98101
receiver: nil,
99102
name: 'body',
100-
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: { node_type: 'keyword_hash_node' } } } do
101-
replace_with node.arguments.arguments.first.elements.map { |element| "@#{element.key.to_value} = #{element.value.to_source}" }.join("\n")
103+
arguments: {
104+
node_type: 'arguments_node',
105+
arguments: { size: 1, first: { node_type: 'keyword_hash_node' } }
106+
} do
107+
replace_with node.arguments.arguments.first.elements.map { |element|
108+
"@#{element.key.to_value} = #{element.value.to_source}"
109+
}
110+
.join("\n")
102111
end
103112
if args.size > 0
104113
mailer_methods[class_name] ||= []
105114
mailer_methods[class_name] << node.name
106-
args_str = args.map { |key, value| ":#{key} => #{value}" }.join(', ')
115+
args_str = args.map { |key, value| ":#{key} => #{value}" }
116+
.join(', ')
107117
append "mail(#{args_str})"
108118
end
109119
end
@@ -134,7 +144,10 @@ def signup_notification(recipient)
134144
# Notifier.deliver(message)
135145
# =>
136146
# message.deliver
137-
with_node node_type: 'call_node', receiver: { not: nil }, name: 'deliver', arguments: { node_type: 'arguments_node', arguments: { size: 1 } } do
147+
with_node node_type: 'call_node',
148+
receiver: { not: nil },
149+
name: 'deliver',
150+
arguments: { node_type: 'arguments_node', arguments: { size: 1 } } do
138151
if mailer_methods[node.receiver.name]
139152
replace_with '{{arguments}}.{{message}}'
140153
end

0 commit comments

Comments
 (0)