@@ -60,12 +60,12 @@ module JSON
60
60
# If *strict* is `true`, unknown properties in the JSON
61
61
# document will raise a parse exception. The default is `false`, so unknown properties
62
62
# are silently ignored.
63
- macro mapping (properties , strict = false )
64
- {% for key, value in properties % }
65
- {% properties [key] = {type: value} unless value.is_a?(HashLiteral ) || value.is_a?(NamedTupleLiteral ) % }
63
+ macro mapping (_properties_ , strict = false )
64
+ {% for key, value in _properties_ % }
65
+ {% _properties_ [key] = {type: value} unless value.is_a?(HashLiteral ) || value.is_a?(NamedTupleLiteral ) % }
66
66
{% end % }
67
67
68
- {% for key, value in properties % }
68
+ {% for key, value in _properties_ % }
69
69
@{{key.id}} : {{value[:type ]}} {{ (value[:nilable ] ? " ?" : " " ).id }}
70
70
71
71
{% if value[:setter ] == nil ? true : value[:setter ] % }
@@ -90,7 +90,7 @@ module JSON
90
90
{% end % }
91
91
92
92
def initialize (% pull : ::JSON ::PullParser )
93
- {% for key, value in properties % }
93
+ {% for key, value in _properties_ % }
94
94
% var{key.id} = nil
95
95
% found{key.id} = false
96
96
{% end % }
@@ -101,7 +101,7 @@ module JSON
101
101
% key_location = % pull.location
102
102
key = % pull.read_object_key
103
103
case key
104
- {% for key, value in properties % }
104
+ {% for key, value in _properties_ % }
105
105
when {{value[:key ] || key.id.stringify}}
106
106
% found{key.id} = true
107
107
@@ -137,15 +137,15 @@ module JSON
137
137
end
138
138
% pull.read_next
139
139
140
- {% for key, value in properties % }
140
+ {% for key, value in _properties_ % }
141
141
{% unless value[:nilable ] || value[:default ] != nil % }
142
142
if % var{key.id}.nil? && ! % found{key.id} && ! ::Union ({{value[:type ]}}).nilable?
143
143
raise ::JSON ::ParseException .new(" Missing json attribute: {{(value[:key] || key).id}}" , *% location)
144
144
end
145
145
{% end % }
146
146
{% end % }
147
147
148
- {% for key, value in properties % }
148
+ {% for key, value in _properties_ % }
149
149
{% if value[:nilable ] % }
150
150
{% if value[:default ] != nil % }
151
151
@{{key.id}} = % found{key.id} ? % var{key.id} : {{value[:default ]}}
@@ -159,7 +159,7 @@ module JSON
159
159
{% end % }
160
160
{% end % }
161
161
162
- {% for key, value in properties % }
162
+ {% for key, value in _properties_ % }
163
163
{% if value[:presence ] % }
164
164
@{{key.id}}_present = % found{key.id}
165
165
{% end % }
@@ -168,7 +168,7 @@ module JSON
168
168
169
169
def to_json (json : ::JSON ::Builder )
170
170
json.object do
171
- {% for key, value in properties % }
171
+ {% for key, value in _properties_ % }
172
172
_{{key.id}} = @{{key.id}}
173
173
174
174
{% unless value[:emit_null ] % }
@@ -216,7 +216,7 @@ module JSON
216
216
217
217
# This is a convenience method to allow invoking `JSON.mapping`
218
218
# with named arguments instead of with a hash/named-tuple literal.
219
- macro mapping (** properties )
220
- ::JSON .mapping({{properties }})
219
+ macro mapping (** _properties_ )
220
+ ::JSON .mapping({{_properties_ }})
221
221
end
222
222
end
0 commit comments