apiql 0.3.0 → 0.3.1
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 +18 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c646102791e4397cfd322014616a3f214c38dde8b7edd37fef3c37c6b84176b
|
4
|
+
data.tar.gz: 90d131a408fb22501e197027f4b05d55b080fbe07fe5c1f7d4f9bf405d3fd988
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 170163dba5b575197a34d1baf4ec38bdd8fdfb67c7742ff924d8bc09d0df5626cb2a203b80bbb9b6fe57cb9ff6eb87848856f17a432391dbca523b0f3a4672c5
|
7
|
+
data.tar.gz: 5bc6a8546e72f75fdd46f06120ea739d247cc2716f1c3fa71e3739f117826d81e859f5ff89202f6fd65d0d17e145754191b4977bae8edf365a3f9684bf02dae2
|
data/apiql.gemspec
CHANGED
data/lib/apiql.rb
CHANGED
@@ -69,7 +69,7 @@ class APIQL
|
|
69
69
|
schema = reg[:rest]
|
70
70
|
|
71
71
|
ptr = pool.pop
|
72
|
-
elsif pool.any? && (reg = schema.match(/\A\s*(?<name>[\w\.]+)(\((?<params
|
72
|
+
elsif pool.any? && (reg = schema.match(/\A\s*(?<name>[\w\.]+)(\((?<params>.*?)\))?(?<rest>.*)\z/m))
|
73
73
|
schema = reg[:rest]
|
74
74
|
|
75
75
|
if reg[:params].nil?
|
@@ -116,11 +116,11 @@ class APIQL
|
|
116
116
|
schema.map do |call|
|
117
117
|
if call.is_a? ::Hash
|
118
118
|
call.each do |function, sub_schema|
|
119
|
-
reg = function.match(/\A(?<name>[\w\.]+)(\((?<params
|
119
|
+
reg = function.match(/\A(?<name>[\w\.]+)(\((?<params>.*?)\))?\z/)
|
120
120
|
raise Error, function unless reg.present?
|
121
121
|
|
122
122
|
function = reg[:name]
|
123
|
-
params = @context.parse_params(reg[:params])
|
123
|
+
params = @context.parse_params(reg[:params].presence)
|
124
124
|
|
125
125
|
@eager_load = eager_loads(sub_schema)
|
126
126
|
data = public_send(function, *params)
|
@@ -135,11 +135,11 @@ class APIQL
|
|
135
135
|
result[function] = @context.render_value(data, sub_schema)
|
136
136
|
end
|
137
137
|
else
|
138
|
-
reg = call.match(/\A(?<name>[\w\.]+)(\((?<params
|
138
|
+
reg = call.match(/\A(?<name>[\w\.]+)(\((?<params>.*?)\))?\z/)
|
139
139
|
raise Error, call unless reg.present?
|
140
140
|
|
141
141
|
function = reg[:name]
|
142
|
-
params = @context.parse_params(reg[:params])
|
142
|
+
params = @context.parse_params(reg[:params].presence)
|
143
143
|
|
144
144
|
@eager_load = ''
|
145
145
|
data = public_send(function, *params)
|
@@ -220,12 +220,16 @@ class APIQL
|
|
220
220
|
schema.each do |field|
|
221
221
|
if field.is_a? Hash
|
222
222
|
field.each do |field, sub_schema|
|
223
|
-
|
224
|
-
|
223
|
+
reg = field.match(/\A(?<name>[\w\.]+)(\((?<params>.*?)\))?\z/)
|
224
|
+
raise Error, field unless reg.present?
|
225
|
+
|
226
|
+
respond[reg[:name]] = render_attribute(reg[:name], reg[:params].presence, sub_schema)
|
225
227
|
end
|
226
228
|
else
|
227
|
-
|
228
|
-
|
229
|
+
reg = field.match(/\A(?<name>[\w\.]+)(\((?<params>.*?)\))?\z/)
|
230
|
+
raise Error, field unless reg.present?
|
231
|
+
|
232
|
+
respond[reg[:name]] = render_attribute(reg[:name], reg[:params].presence)
|
229
233
|
end
|
230
234
|
end
|
231
235
|
|
@@ -234,9 +238,8 @@ class APIQL
|
|
234
238
|
|
235
239
|
private
|
236
240
|
|
237
|
-
def get_field(field)
|
238
|
-
if
|
239
|
-
field, params = field
|
241
|
+
def get_field(field, params = nil)
|
242
|
+
if params.present?
|
240
243
|
params = @context.parse_params(params)
|
241
244
|
end
|
242
245
|
|
@@ -277,8 +280,8 @@ class APIQL
|
|
277
280
|
end
|
278
281
|
end
|
279
282
|
|
280
|
-
def render_attribute(field, schema = nil)
|
281
|
-
data = get_field(field)
|
283
|
+
def render_attribute(field, params = nil, schema = nil)
|
284
|
+
data = get_field(field, params)
|
282
285
|
|
283
286
|
if data.is_a?(Hash) && schema.present?
|
284
287
|
respond = {}
|
@@ -309,7 +312,7 @@ class APIQL
|
|
309
312
|
end
|
310
313
|
|
311
314
|
class HashEntity < Entity
|
312
|
-
def get_field(field)
|
315
|
+
def get_field(field, params = nil)
|
313
316
|
object[field.to_sym]
|
314
317
|
end
|
315
318
|
end
|