jsonapi_compliable 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +8 -0
  3. data/docs/Jsonapi.html +1 -1
  4. data/docs/Jsonapi/ResourceGenerator.html +13 -123
  5. data/docs/JsonapiCompliable.html +2 -2
  6. data/docs/JsonapiCompliable/Adapters.html +1 -1
  7. data/docs/JsonapiCompliable/Adapters/Abstract.html +193 -17
  8. data/docs/JsonapiCompliable/Adapters/ActiveRecord.html +106 -20
  9. data/docs/JsonapiCompliable/Adapters/ActiveRecordSideloading.html +4 -4
  10. data/docs/JsonapiCompliable/Adapters/Null.html +2 -2
  11. data/docs/JsonapiCompliable/Base.html +2 -2
  12. data/docs/JsonapiCompliable/Deserializer.html +25 -23
  13. data/docs/JsonapiCompliable/Errors.html +1 -1
  14. data/docs/JsonapiCompliable/Errors/BadFilter.html +1 -1
  15. data/docs/JsonapiCompliable/Errors/StatNotFound.html +1 -1
  16. data/docs/JsonapiCompliable/Errors/UnsupportedPageSize.html +1 -1
  17. data/docs/JsonapiCompliable/Errors/ValidationError.html +1 -1
  18. data/docs/JsonapiCompliable/Extensions.html +1 -1
  19. data/docs/JsonapiCompliable/Extensions/BooleanAttribute.html +1 -1
  20. data/docs/JsonapiCompliable/Extensions/BooleanAttribute/ClassMethods.html +1 -1
  21. data/docs/JsonapiCompliable/Extensions/ExtraAttribute.html +1 -1
  22. data/docs/JsonapiCompliable/Extensions/ExtraAttribute/ClassMethods.html +1 -1
  23. data/docs/JsonapiCompliable/Query.html +1 -1
  24. data/docs/JsonapiCompliable/Rails.html +1 -1
  25. data/docs/JsonapiCompliable/Resource.html +261 -109
  26. data/docs/JsonapiCompliable/Scope.html +1 -1
  27. data/docs/JsonapiCompliable/Scoping.html +1 -1
  28. data/docs/JsonapiCompliable/Scoping/Base.html +1 -1
  29. data/docs/JsonapiCompliable/Scoping/DefaultFilter.html +1 -1
  30. data/docs/JsonapiCompliable/Scoping/ExtraFields.html +1 -1
  31. data/docs/JsonapiCompliable/Scoping/Filter.html +1 -1
  32. data/docs/JsonapiCompliable/Scoping/Filterable.html +1 -1
  33. data/docs/JsonapiCompliable/Scoping/Paginate.html +1 -1
  34. data/docs/JsonapiCompliable/Scoping/Sort.html +1 -1
  35. data/docs/JsonapiCompliable/SerializableTempId.html +1 -1
  36. data/docs/JsonapiCompliable/Sideload.html +691 -124
  37. data/docs/JsonapiCompliable/Stats.html +1 -1
  38. data/docs/JsonapiCompliable/Stats/DSL.html +1 -1
  39. data/docs/JsonapiCompliable/Stats/Payload.html +1 -1
  40. data/docs/JsonapiCompliable/Util.html +1 -1
  41. data/docs/JsonapiCompliable/Util/FieldParams.html +1 -1
  42. data/docs/JsonapiCompliable/Util/Hash.html +1 -1
  43. data/docs/JsonapiCompliable/Util/IncludeParams.html +1 -1
  44. data/docs/JsonapiCompliable/Util/Persistence.html +22 -12
  45. data/docs/JsonapiCompliable/Util/RelationshipPayload.html +1 -1
  46. data/docs/JsonapiCompliable/Util/RenderOptions.html +1 -1
  47. data/docs/JsonapiCompliable/Util/ValidationResponse.html +1 -1
  48. data/docs/_index.html +1 -1
  49. data/docs/file.README.html +11 -14
  50. data/docs/index.html +11 -14
  51. data/docs/method_list.html +368 -280
  52. data/docs/top-level-namespace.html +1 -1
  53. data/lib/jsonapi_compliable/sideload.rb +38 -17
  54. data/lib/jsonapi_compliable/util/relationship_payload.rb +1 -0
  55. data/lib/jsonapi_compliable/version.rb +1 -1
  56. metadata +3 -3
@@ -100,7 +100,7 @@
100
100
  </div>
101
101
 
102
102
  <div id="footer">
103
- Generated on Wed Jun 7 10:15:09 2017 by
103
+ Generated on Thu Sep 28 17:28:09 2017 by
104
104
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
105
  0.9.9 (ruby-2.3.0).
106
106
  </div>
@@ -43,6 +43,21 @@ module JsonapiCompliable
43
43
  extend @resource_class.config[:adapter].sideloading_module
44
44
  end
45
45
 
46
+ # @api private
47
+ def self.max_depth
48
+ @max_depth || 2
49
+ end
50
+
51
+ # Set maximum levels of sideload recursion
52
+ # /authors?comments.authors would be one level
53
+ # /authors?comments.authors.comments.authors would be two levels
54
+ # etc
55
+ #
56
+ # Default max depth is 2
57
+ def self.max_depth=(val)
58
+ @max_depth = val
59
+ end
60
+
46
61
  # @see #resource_class
47
62
  # @return [Resource] an instance of +#resource_class+
48
63
  def resource
@@ -331,6 +346,19 @@ module JsonapiCompliable
331
346
  @sideloads[name]
332
347
  end
333
348
 
349
+ # @api private
350
+ def all_sideloads
351
+ {}.tap do |all|
352
+ if polymorphic?
353
+ polymorphic_groups.each_pair do |type, sl|
354
+ all.merge!(sl.resource.sideloading.all_sideloads)
355
+ end
356
+ else
357
+ all.merge!(@sideloads.merge(resource.sideloading.sideloads))
358
+ end
359
+ end
360
+ end
361
+
334
362
  # Looks at all nested sideload, and all nested sideloads for the
335
363
  # corresponding Resources, and returns an Include Directive hash
336
364
  #
@@ -354,27 +382,20 @@ module JsonapiCompliable
354
382
  #
355
383
  # @return [Hash] The nested include hash
356
384
  # @api private
357
- def to_hash(processed = [])
358
- # Cut off at 5 recursions
359
- if processed.select { |p| p == self }.length == 5
360
- return { name => {} }
361
- end
362
- processed << self
385
+ def to_hash(depth_chain = [], parent = nil)
386
+ depth = depth_chain.select { |arr| arr == [parent, self] }.length
387
+ return {} if depth >= self.class.max_depth
363
388
 
364
- result = { name => {} }.tap do |hash|
365
- @sideloads.each_pair do |key, sideload|
366
- hash[name][key] = sideload.to_hash(processed)[key] || {}
389
+ unless (parent && parent.name == :base) || name == :base
390
+ depth_chain += [[parent, self]]
391
+ end
367
392
 
368
- if sideload.polymorphic?
369
- sideload.polymorphic_groups.each_pair do |type, sl|
370
- hash[name][key].merge!(nested_sideload_hash(sl, processed))
371
- end
372
- else
373
- hash[name][key].merge!(nested_sideload_hash(sideload, processed))
374
- end
393
+ { name => {} }.tap do |hash|
394
+ all_sideloads.each_pair do |key, sl|
395
+ sideload_hash = sl.to_hash(depth_chain, self)
396
+ hash[name].merge!(sideload_hash)
375
397
  end
376
398
  end
377
- result
378
399
  end
379
400
 
380
401
  # @api private
@@ -47,6 +47,7 @@ module JsonapiCompliable
47
47
  type = relationship_payload[:meta][:jsonapi_type]
48
48
  sideload = sideload.polymorphic_child_for_type(type)
49
49
  end
50
+ relationship_payload[:meta][:method] ||= :update
50
51
 
51
52
  {
52
53
  sideload: sideload,
@@ -1,3 +1,3 @@
1
1
  module JsonapiCompliable
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi_compliable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-09-18 00:00:00.000000000 Z
12
+ date: 2017-09-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jsonapi-serializable
@@ -265,7 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
265
265
  version: '0'
266
266
  requirements: []
267
267
  rubyforge_project:
268
- rubygems_version: 2.6.11
268
+ rubygems_version: 2.6.13
269
269
  signing_key:
270
270
  specification_version: 4
271
271
  summary: Easily build jsonapi.org-compatible APIs