File tree 1 file changed +20
-5
lines changed
1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -20,9 +20,22 @@ def initialize(gemfile)
20
20
end
21
21
22
22
def perform
23
- # Remove line breaks to ensure consistent spacing
23
+ remove_line_breaks
24
+ sort_gems_and_groups
25
+ add_gem_groups_to_gemfile
26
+ add_line_breaks
27
+ cleanup
28
+
29
+ File . open ( gemfile , "w+" ) { _1 . write new_lines . join }
30
+ end
31
+
32
+ private
33
+
34
+ def remove_line_breaks
24
35
current_lines . delete ( "\n " )
36
+ end
25
37
38
+ def sort_gems_and_groups
26
39
current_lines . each do |line |
27
40
if line . starts_with? ( /group/ )
28
41
@current_group = line
@@ -42,8 +55,9 @@ def perform
42
55
@current_group = nil
43
56
end
44
57
end
58
+ end
45
59
46
- # Add consolidated gem groups to new Gemfile
60
+ def add_gem_groups_to_gemfile
47
61
gem_groups . keys . each do |group |
48
62
gems = gem_groups [ group ]
49
63
@@ -59,8 +73,9 @@ def perform
59
73
end
60
74
end
61
75
end
76
+ end
62
77
63
- # Conditionally add line breaks
78
+ def add_line_breaks
64
79
new_lines . each_with_index do |line , index |
65
80
previous_line = new_lines [ index - 1 ] if index > 0
66
81
next_line = new_lines [ index + 1 ]
@@ -106,13 +121,13 @@ def perform
106
121
107
122
new_lines . insert ( marker_offset , "\n " )
108
123
end
124
+ end
109
125
126
+ def cleanup
110
127
# Remove last line
111
128
if /\n / . match? ( new_lines . last )
112
129
new_lines . pop
113
130
end
114
-
115
- File . open ( gemfile , "w+" ) { _1 . write new_lines . join }
116
131
end
117
132
end
118
133
end
You can’t perform that action at this time.
0 commit comments