apiql 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/apiql.gemspec +1 -1
- data/lib/apiql.rb +77 -25
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 456ef97a233db53a9e51b2fe04e55c8e360e2f12077e745ac1527278a294dd50
|
4
|
+
data.tar.gz: 79d50b2cf5b3bc79b3eeca1bed1b3d401a1a2fb76ef1cf5b4ac7ac1d9e3dbc05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96f51297e1bc429c789f3614deb3a959a2746fed188b2197cf6a92e31233dbb9f5d4e57815775f9c12478c17bee34673573ae32a508854ab1cd576ed16b9ab4d
|
7
|
+
data.tar.gz: a2c0f57660d4be5f0ac9e76fa8814d038fa748dde5bd38f147a0fd3f7355aff15e161d853c0a21bfb0a02687adddad6359e2b448973f47f8bd2b34fe7a5e4c0f
|
data/apiql.gemspec
CHANGED
data/lib/apiql.rb
CHANGED
@@ -133,6 +133,7 @@ class APIQL
|
|
133
133
|
if call.is_a? Hash
|
134
134
|
call.each do |function, sub_schema|
|
135
135
|
next if function.include? '('
|
136
|
+
function = function.split(':').last.strip if function.include? ':'
|
136
137
|
function = function.split('.').first if function.include? '.'
|
137
138
|
|
138
139
|
sub = eager_loads(sub_schema)
|
@@ -165,36 +166,67 @@ class APIQL
|
|
165
166
|
ptr = result
|
166
167
|
pool = []
|
167
168
|
|
169
|
+
push_key = lambda do |key, subtree = false|
|
170
|
+
ptr.each_with_index do |e, index|
|
171
|
+
if e.is_a?(::Hash)
|
172
|
+
return e[key] if e[key]
|
173
|
+
elsif e == key
|
174
|
+
if subtree
|
175
|
+
ptr[index] = { key => (p = []) }
|
176
|
+
return p
|
177
|
+
end
|
178
|
+
return
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
if subtree
|
183
|
+
ptr.push(key => (p = []))
|
184
|
+
return p
|
185
|
+
else
|
186
|
+
ptr.push(key)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
last_key = nil
|
191
|
+
|
168
192
|
while schema.present? do
|
169
193
|
if reg = schema.match(/\A\s*\{(?<rest>.*)\z/m) # {
|
170
194
|
schema = reg[:rest]
|
171
195
|
|
172
196
|
pool.push(ptr)
|
173
|
-
|
174
|
-
ptr
|
197
|
+
|
198
|
+
ptr = push_key.call(last_key, true)
|
175
199
|
elsif reg = schema.match(/\A\s*\}(?<rest>.*)\z/m) # }
|
176
200
|
schema = reg[:rest]
|
177
201
|
|
178
202
|
ptr = pool.pop
|
179
|
-
elsif pool.any?
|
180
|
-
|
203
|
+
elsif pool.any?
|
204
|
+
if reg = schema.match(/\A\s*((?<alias>[\w\.]+):\s*)?(?<name>[\w\.]+)(\((?<params>.*?)\))?(?<rest>.*)\z/m)
|
205
|
+
schema = reg[:rest]
|
206
|
+
|
207
|
+
key = reg[:alias].present? ? "#{reg[:alias]}: #{reg[:name]}" : reg[:name]
|
208
|
+
key += "(#{reg[:params]})" unless reg[:params].nil?
|
181
209
|
|
182
|
-
|
183
|
-
|
210
|
+
push_key.call(key)
|
211
|
+
|
212
|
+
last_key = key
|
184
213
|
else
|
185
|
-
|
214
|
+
raise Error, schema
|
186
215
|
end
|
187
|
-
|
188
|
-
ptr.push(key)
|
189
216
|
elsif reg = schema.match(/\A\s*((?<alias>[\w\.]+):\s*)?(?<name>[\w\.]+)(\((?<params>((\w+)(\s*\,\s*\w+)*))?\))?\s*\{(?<rest>.*)\z/m)
|
190
217
|
schema = reg[:rest]
|
191
218
|
|
219
|
+
key = "#{reg[:alias] || reg[:name]}: #{reg[:name]}(#{reg[:params]})"
|
220
|
+
|
192
221
|
pool.push(ptr)
|
193
|
-
|
222
|
+
|
223
|
+
ptr = push_key.call(key, true)
|
194
224
|
elsif reg = schema.match(/\A\s*((?<alias>[\w\.]+):\s*)?(?<name>[\w\.]+)(\((?<params>((\w+)(\s*\,\s*\w+)*))?\))?\s*\n?(?<rest>.*)\z/m)
|
195
225
|
schema = reg[:rest]
|
196
226
|
|
197
|
-
|
227
|
+
key = "#{reg[:alias] || reg[:name]}: #{reg[:name]}(#{reg[:params]})"
|
228
|
+
|
229
|
+
push_key.call(key)
|
198
230
|
else
|
199
231
|
raise Error, schema
|
200
232
|
end
|
@@ -240,9 +272,13 @@ class APIQL
|
|
240
272
|
end
|
241
273
|
end
|
242
274
|
|
243
|
-
|
244
|
-
|
245
|
-
|
275
|
+
if result[name].is_a? ::Hash
|
276
|
+
result = result.deep_merge({
|
277
|
+
name => @context.render_value(data, sub_schema)
|
278
|
+
})
|
279
|
+
else
|
280
|
+
result[name] = @context.render_value(data, sub_schema)
|
281
|
+
end
|
246
282
|
end
|
247
283
|
else
|
248
284
|
reg = call.match(/\A((?<alias>[\w\.]+):\s*)?(?<name>[\w\.]+)(\((?<params>.*?)\))?\z/)
|
@@ -262,9 +298,13 @@ class APIQL
|
|
262
298
|
data = nil
|
263
299
|
end
|
264
300
|
|
265
|
-
|
266
|
-
|
267
|
-
|
301
|
+
if result[name].is_a? ::Hash
|
302
|
+
result = result.deep_merge({
|
303
|
+
name => data
|
304
|
+
})
|
305
|
+
else
|
306
|
+
result[name] = data
|
307
|
+
end
|
268
308
|
end
|
269
309
|
end
|
270
310
|
|
@@ -314,20 +354,32 @@ class APIQL
|
|
314
354
|
schema.each do |field|
|
315
355
|
if field.is_a? Hash
|
316
356
|
field.each do |field, sub_schema|
|
317
|
-
reg = field.match(/\A(?<name>[\w\.]+)(\((?<params>.*?)\))?\z/)
|
357
|
+
reg = field.match(/\A((?<alias>[\w\.]+):\s*)?(?<name>[\w\.]+)(\((?<params>.*?)\))?\z/)
|
318
358
|
raise Error, field unless reg.present?
|
319
359
|
|
320
|
-
|
321
|
-
|
322
|
-
|
360
|
+
name = reg[:alias] || reg[:name]
|
361
|
+
|
362
|
+
if respond[name].is_a? ::Hash
|
363
|
+
respond = respond.deep_merge({
|
364
|
+
name => render_attribute(reg[:name], reg[:params].presence, sub_schema)
|
365
|
+
})
|
366
|
+
else
|
367
|
+
respond[name] = render_attribute(reg[:name], reg[:params].presence, sub_schema)
|
368
|
+
end
|
323
369
|
end
|
324
370
|
else
|
325
|
-
reg = field.match(/\A(?<name>[\w\.]+)(\((?<params>.*?)\))?\z/)
|
371
|
+
reg = field.match(/\A((?<alias>[\w\.]+):\s*)?(?<name>[\w\.]+)(\((?<params>.*?)\))?\z/)
|
326
372
|
raise Error, field unless reg.present?
|
327
373
|
|
328
|
-
|
329
|
-
|
330
|
-
|
374
|
+
name = reg[:alias] || reg[:name]
|
375
|
+
|
376
|
+
if respond[name].is_a? ::Hash
|
377
|
+
respond = respond.deep_merge({
|
378
|
+
name => render_attribute(reg[:name], reg[:params].presence)
|
379
|
+
})
|
380
|
+
else
|
381
|
+
respond[name] = render_attribute(reg[:name], reg[:params].presence)
|
382
|
+
end
|
331
383
|
end
|
332
384
|
end
|
333
385
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apiql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Silchenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|