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
57
58
59
60
61
|
# File 'lib/jsoncop/generator.rb', line 27
def json_cop_template
result = "// MARK: - JSONCop-Start\n\n"
@models.each do |model|
result += <<-JSONCOP
extension #{model.name} {
static func parse(json: Any) -> #{model.name}? {
guard let json = json as? [String: Any] else { return nil }
guard #{json_parsing_template model} else { return nil }
return #{model.name}(#{model.key_value_pair})
}
static func parses(jsons: Any) -> [#{model.name}] {
guard let jsons = jsons as? [[String: Any]] else { return [] }
return jsons.flatMap(parse)
}
}
JSONCOP
end
result += "// JSONCop-End"
result
end
|