json_api_ruby 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2583d3425ef36b085c8a7d2c58569b138f695462
4
- data.tar.gz: 4a23def762768101841b2719d5862fc721c0d1d5
3
+ metadata.gz: c5dceae1c4696a3b82d185b7d649c75a54b9970b
4
+ data.tar.gz: 0bc9d17129bfe3ef885ea78ad1313c56b151927d
5
5
  SHA512:
6
- metadata.gz: 706bfc6a97b2d8fccc355e91162f5a0a34f4a54299cd5f5dd4864d48f7e8f7e4d0bb084e32d679eed0b848bfbd3e7f890e7d2fb1f7719ceeb2fce855d5d78394
7
- data.tar.gz: 683c5fab664a31b4817fcaa2629a1a5003c8b8fd4de95cb9889bcd5a6e40314bd04a979a6e4b7768bc2958ba9bba1725ee2c6a782830e3a6443470f66ef0e28c
6
+ metadata.gz: e16b110f1359c748d9868ff1c7d487a1855648a1519ff46b79c01e6ab177725d5e9b43f9e01969cda08ad87a213419e02ad74232f6f54c1983563897db8849b6
7
+ data.tar.gz: 08ff527bfe60cc369fd1a68c04d251194721ba01123bb1e1dbc897e6fb229fab38d39eb7c155de2d757d7efd7ff14673ed75c665be2665bc54d16a9fdb31483c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ 0.4.4
2
+ Fixed an issue with complex includes
3
+
1
4
  0.4.3
2
5
  Removed the constraint on activesupport 3. Should be >= 3 not ~> 3
3
6
 
@@ -11,19 +11,13 @@ module JsonApi
11
11
  first_include = self.new
12
12
 
13
13
  split_includes = Array(includes).map{|inc| inc.to_s.split('.')}
14
- if split_includes.blank?
15
- return first_include
16
- end
17
-
18
- first_array = Array(split_includes.first)
19
- other_arrays = split_includes[1..-1]
20
- zipped = first_array.zip(*other_arrays)
21
- first_array = zipped.shift
22
- first_include.includes = first_array.uniq.compact
14
+ split_includes = ArrayTransposer.new(split_includes).transpose_array
15
+ first_array = split_includes.shift
16
+ first_include.includes = Array(first_array).uniq.compact
23
17
 
24
- zipped.inject(first_include) do |base_include, object_name|
18
+ split_includes.inject(first_include) do |base_include, sub_array|
25
19
  new_include = self.new
26
- new_include.includes = object_name.uniq.compact
20
+ new_include.includes = sub_array.uniq.compact
27
21
  base_include.next = new_include
28
22
  new_include
29
23
  end
@@ -42,5 +36,41 @@ module JsonApi
42
36
  def next
43
37
  @next || self.class.new
44
38
  end
39
+
40
+ end
41
+
42
+ class ArrayTransposer
43
+ attr_reader :array
44
+
45
+ def initialize(array)
46
+ @array = Array(array)
47
+ end
48
+
49
+ def transpose_array
50
+ padded_sub_arrays.transpose
51
+ end
52
+
53
+ def padded_sub_arrays
54
+ max_length = largest_sub_array_length
55
+ array.map do |sub_array|
56
+ sub_array.extend(ArrayPadder)
57
+ sub_array.pad(max_length)
58
+ end
59
+ end
60
+
61
+ def largest_sub_array_length
62
+ largest_count = 0
63
+ array.each do |sub_array|
64
+ largest_count = sub_array.count if sub_array.length > largest_count
65
+ end
66
+ largest_count
67
+ end
68
+ end
69
+
70
+ # Meant to be extended within an Array instance
71
+ module ArrayPadder
72
+ def pad(length)
73
+ self + self.class.new(length - self.length) { nil }
74
+ end
45
75
  end
46
76
  end
@@ -1,3 +1,3 @@
1
1
  module JsonApi
2
- VERSION = '0.4.3'
2
+ VERSION = '0.4.4'
3
3
  end
@@ -25,10 +25,10 @@ describe JsonApi::Includes do
25
25
 
26
26
  context 'complex includes' do
27
27
  subject(:parsed_includes) do
28
- described_class.parse_includes(['thingone.thingtwo.thingthree', 'thingone.thingfour', 'thingone.thingtwo.thingfive', 'thingsix.thingseven'])
28
+ described_class.parse_includes(['thingeight', 'thingnine', 'thingone.thingtwo.thingthree', 'thingone.thingfour', 'thingone.thingtwo.thingfive', 'thingsix.thingseven'])
29
29
  end
30
30
 
31
- specify { expect(parsed_includes.includes).to eq ['thingone', 'thingsix'] }
31
+ specify { expect(parsed_includes.includes).to eq ['thingeight', 'thingnine', 'thingone', 'thingsix'] }
32
32
  specify { expect(parsed_includes.next.includes).to eq ['thingtwo', 'thingfour', 'thingseven'] }
33
33
  specify { expect(parsed_includes.next.next.includes).to eq ['thingthree', 'thingfive'] }
34
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_api_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tracey Eubanks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-02 00:00:00.000000000 Z
11
+ date: 2016-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport