7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/schema_test/collapser.rb', line 7
def output
result = []
i = 0
while i < @lines.length
line = @lines[i]
if line.match?(/#{DISABLE_RUBOCOP_COMMENT}/) &&
i + 1 < @lines.length && @lines[i + 1].match?(/#{OPENING_COMMENT}/)
i += 1
next
end
if line =~ /\A(\s*)(\w+)\(\s*#{OPENING_COMMENT}/
indent = $1
method_name = $2
json_var = @lines[i + 1].strip.sub(/,\z/, '')
content_lines = []
j = i + 2
while j < @lines.length && !@lines[j].match?(/#{CLOSING_COMMENT}/)
content_lines << @lines[j]
j += 1
end
end_index = j
joined = content_lines.map(&:strip).join(' ')
name = joined.match(/:(\w+),/)[1]
version_match = joined.match(/:version\s*=>\s*([^,}]+)/)
version = version_match[1].strip
result << "#{indent}#{method_name}(#{json_var}, :#{name}, version: #{version})"
i = end_index + 1
if i < @lines.length && @lines[i].match?(/#{ENABLE_RUBOCOP_COMMENT}/)
i += 1
end
else
result << line
i += 1
end
end
result.join("\n") + "\n"
end
|