apiql 0.3.0 → 0.3.1

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 +18 -15
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f34e609be9a7132527a772ee95d0e7dd4e43aff4bb7d8f9fd43010f73e9632e
4
- data.tar.gz: 1194eed934b4c0f26084dc0cdec5beac7d51967236e1b6438efa176d176cfdb2
3
+ metadata.gz: 1c646102791e4397cfd322014616a3f214c38dde8b7edd37fef3c37c6b84176b
4
+ data.tar.gz: 90d131a408fb22501e197027f4b05d55b080fbe07fe5c1f7d4f9bf405d3fd988
5
5
  SHA512:
6
- metadata.gz: adca6b4acf505f3a281a352640dbabb23a05b9ded7a9ddd99c10d64f0cbba1b67b054a66e048cbdd0f59c164f9fa2b850c3f8693cf0ec92ad967326e87639ee1
7
- data.tar.gz: 0c1c05a98a7cb45868e3d0f3118b4d4ccf87c475e9e88aa84cb49808005ee5f45cdc1df9595eef0be5f5c3f7087213f8ecaeca97e5fad45733dbdf8280a28677
6
+ metadata.gz: 170163dba5b575197a34d1baf4ec38bdd8fdfb67c7742ff924d8bc09d0df5626cb2a203b80bbb9b6fe57cb9ff6eb87848856f17a432391dbca523b0f3a4672c5
7
+ data.tar.gz: 5bc6a8546e72f75fdd46f06120ea739d247cc2716f1c3fa71e3739f117826d81e859f5ff89202f6fd65d0d17e145754191b4977bae8edf365a3f9684bf02dae2
data/apiql.gemspec CHANGED
@@ -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.3.0'
7
+ spec.version = '0.3.1'
8
8
  spec.authors = ['Dmitry Silchenko']
9
9
  spec.email = ['dmitry@desofto.com']
10
10
 
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>.*)\))?(?<rest>.*)\z/m))
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>.*)\))?\z/)
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>.*)\))?\z/)
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
- name = field.is_a?(Array) ? field.first : field
224
- respond[name] = render_attribute(field, sub_schema)
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
- name = field.is_a?(Array) ? field.first : field
228
- respond[name] = render_attribute(field)
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 field.is_a? Array
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Silchenko