apiql 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/apiql.gemspec +1 -1
  3. data/lib/apiql.rb +77 -25
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be1cd2e607d5b0b9f400d217c227a53826f20e5904db4caef949978580be45cf
4
- data.tar.gz: cbd052428a30d779a3ab3670ca60eebf15fe095df867a7f3d3f1d19c35b7663d
3
+ metadata.gz: 456ef97a233db53a9e51b2fe04e55c8e360e2f12077e745ac1527278a294dd50
4
+ data.tar.gz: 79d50b2cf5b3bc79b3eeca1bed1b3d401a1a2fb76ef1cf5b4ac7ac1d9e3dbc05
5
5
  SHA512:
6
- metadata.gz: b583b6f640c5113d3735d90358375d20cd702382b9ca6815d85a70a15473ccac3ce683cd029fe3abcb7c0e812521ff800c4c7ca3291864939592225095449723
7
- data.tar.gz: 7c6090d8ab1e9ea06a181ed7c397cea36c4f6bbd0849f55f45f03fbe1506de24c06ea9a1ad3aebd8959189bd3c3ed9547434eeb56d44a0552e907fcbb1dca124
6
+ metadata.gz: 96f51297e1bc429c789f3614deb3a959a2746fed188b2197cf6a92e31233dbb9f5d4e57815775f9c12478c17bee34673573ae32a508854ab1cd576ed16b9ab4d
7
+ data.tar.gz: a2c0f57660d4be5f0ac9e76fa8814d038fa748dde5bd38f147a0fd3f7355aff15e161d853c0a21bfb0a02687adddad6359e2b448973f47f8bd2b34fe7a5e4c0f
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'apiql'
7
- spec.version = '0.4.4'
7
+ spec.version = '0.4.5'
8
8
  spec.authors = ['Dmitry Silchenko']
9
9
  spec.email = ['dmitry@desofto.com']
10
10
 
@@ -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
- key = ptr.pop
174
- ptr.push(key => (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? && (reg = schema.match(/\A\s*(?<name>[\w\.]+)(\((?<params>.*?)\))?(?<rest>.*)\z/m))
180
- schema = reg[:rest]
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
- if reg[:params].nil?
183
- key = reg[:name]
210
+ push_key.call(key)
211
+
212
+ last_key = key
184
213
  else
185
- key = "#{reg[:name]}(#{reg[:params]})"
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
- ptr.push("#{reg[:alias] || reg[:name]}: #{reg[:name]}(#{reg[:params]})" => (ptr = []))
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
- ptr.push("#{reg[:alias] || reg[:name]}: #{reg[:name]}(#{reg[:params]})")
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
- result = result.deep_merge({
244
- name => @context.render_value(data, sub_schema)
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
- result = result.deep_merge({
266
- name => data
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
- respond = respond.deep_merge({
321
- reg[:name] => render_attribute(reg[:name], reg[:params].presence, sub_schema)
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
- respond = respond.deep_merge({
329
- reg[:name] => render_attribute(reg[:name], reg[:params].presence)
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
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-23 00:00:00.000000000 Z
11
+ date: 2018-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler