apiql 0.3.2 → 0.3.3

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 +40 -23
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ac6431ebb996c5b4b6cdba16b98959d0940e2e49639f7ca4151ad661adaf68b
4
- data.tar.gz: 496a09974536e4cab2b0c24991810976dbb1ba0c1970d1eebb6fe444a5eef44b
3
+ metadata.gz: bdbc7a6ae370719e2cf99317eecb62b1d55cb102f5e6c139efbaf3f834af3fe9
4
+ data.tar.gz: fe6cd1969365185700487d36ea7f4daaad0c3adbb344207ea14237a7299af709
5
5
  SHA512:
6
- metadata.gz: 2d9b772486c1ff3acf01b3a38bdd546cd56d2225ea7355a7422fd9600754e1888acefe49546d0067dece0b783977bc40a55dbc8557018a5d6d9faa45d87d4085
7
- data.tar.gz: f6b11444f78329b6dc5557b33d9ab2578c8379d072bec623d23dbdf69affa420568d4e2839090254f4ee74784a2c7be309ea26863afd91ec84c24c6f9b488a66
6
+ metadata.gz: 4e88a8c04a5f968a4a3ef2ce409ed68df1791103ff04732550b88cec6e6936145ae79054d99ad8102dbc8b448f015ddda9d399d28aa48e47e9762f78d2cc7fb1
7
+ data.tar.gz: 8adb7c155531070ea9a33292d0243fe0c4007f3f3c90da09103199ba25f0a4d323316cd7d215984559fe65087022e78a98f73fdb8d0e228f698698b7f9b61bf8
@@ -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.2'
7
+ spec.version = '0.3.3'
8
8
  spec.authors = ['Dmitry Silchenko']
9
9
  spec.email = ['dmitry@desofto.com']
10
10
 
@@ -41,6 +41,28 @@ class APIQL
41
41
  value.is_a?(Hash)
42
42
  end
43
43
 
44
+ def eager_loads(schema)
45
+ result = []
46
+
47
+ schema&.each do |call|
48
+ if call.is_a? Hash
49
+ call.each do |function, sub_schema|
50
+ next if function.include? '('
51
+ function = function.split('.').first if function.include? '.'
52
+
53
+ sub = eager_loads(sub_schema)
54
+ if sub.present?
55
+ result.push(function => sub)
56
+ else
57
+ result.push function
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ result
64
+ end
65
+
44
66
  private
45
67
 
46
68
  def redis
@@ -122,7 +144,7 @@ class APIQL
122
144
  function = reg[:name]
123
145
  params = @context.parse_params(reg[:params].presence)
124
146
 
125
- @eager_load = eager_loads(sub_schema)
147
+ @eager_load = APIQL::eager_loads(sub_schema)
126
148
  data = public_send(function, *params)
127
149
  if @eager_load.present? && !data.is_a?(::Hash) && !data.is_a?(::Array)
128
150
  if data.respond_to?(:each) && data.respond_to?(:map)
@@ -160,28 +182,6 @@ class APIQL
160
182
 
161
183
  private
162
184
 
163
- def eager_loads(schema)
164
- result = []
165
-
166
- schema.each do |call|
167
- if call.is_a? Hash
168
- call.each do |function, sub_schema|
169
- next if function.include? '('
170
- function = function.split('.').first if function.include? '.'
171
-
172
- sub = eager_loads(sub_schema)
173
- if sub.present?
174
- result.push(function => sub)
175
- else
176
- result.push function
177
- end
178
- end
179
- end
180
- end
181
-
182
- result
183
- end
184
-
185
185
  class Entity
186
186
  class << self
187
187
  attr_reader :apiql_attributes
@@ -280,9 +280,26 @@ class APIQL
280
280
  end
281
281
  end
282
282
 
283
+ def eager_load
284
+ result = @eager_load
285
+
286
+ @eager_load = nil
287
+
288
+ result
289
+ end
290
+
283
291
  def render_attribute(field, params = nil, schema = nil)
292
+ @eager_load = APIQL::eager_loads(schema)
284
293
  data = get_field(field, params)
285
294
 
295
+ if @eager_load.present? && !data.is_a?(::Hash) && !data.is_a?(::Array)
296
+ if data.respond_to?(:each) && data.respond_to?(:map)
297
+ unless data.loaded?
298
+ data = data.eager_load(eager_load)
299
+ end
300
+ end
301
+ end
302
+
286
303
  if data.is_a?(Hash) && schema.present?
287
304
  respond = {}
288
305
 
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.3.2
4
+ version: 0.3.3
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-07-19 00:00:00.000000000 Z
11
+ date: 2018-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler