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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/json_api_ruby/includes.rb +41 -11
- data/lib/json_api_ruby/version.rb +1 -1
- data/spec/json_api_ruby/includes_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5dceae1c4696a3b82d185b7d649c75a54b9970b
|
4
|
+
data.tar.gz: 0bc9d17129bfe3ef885ea78ad1313c56b151927d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e16b110f1359c748d9868ff1c7d487a1855648a1519ff46b79c01e6ab177725d5e9b43f9e01969cda08ad87a213419e02ad74232f6f54c1983563897db8849b6
|
7
|
+
data.tar.gz: 08ff527bfe60cc369fd1a68c04d251194721ba01123bb1e1dbc897e6fb229fab38d39eb7c155de2d757d7efd7ff14673ed75c665be2665bc54d16a9fdb31483c
|
data/CHANGELOG.md
CHANGED
@@ -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
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
18
|
+
split_includes.inject(first_include) do |base_include, sub_array|
|
25
19
|
new_include = self.new
|
26
|
-
new_include.includes =
|
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
|
@@ -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.
|
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-
|
11
|
+
date: 2016-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|