jsonapi-materializer 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b51f422840742a6b80b48de2c10d75b2530a630d13e0caecb0c598f79089081e
|
4
|
+
data.tar.gz: ffbf502f4377b1814cb6ba7c8f7d5b3cd01d792ccc4fa047ccd1e2c448f83f19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bb8dc1d59f884f503c4e6f993c331a69d41b7e7619f34fa2296f5cb0597e82cf128d55f27b15f2523e6d7ea1c603ed4cb8abb87c65da3d78dd2197484e4348e
|
7
|
+
data.tar.gz: 7689dec65ec8f3a81751c054345ae19e51d5ef1dd64245ce7bccc6226b373f168f69eeb1c51254f635a69d89e5ae70ea176eb708d98f7e234ef013a507c57756
|
@@ -22,38 +22,16 @@ module JSONAPI
|
|
22
22
|
|
23
23
|
def as_json(*)
|
24
24
|
{
|
25
|
-
links:
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
self: (links_self unless total_pages.zero?),
|
30
|
-
next: (links_pagination.expand(offset: next_page, limit: limit_value).to_s unless total_pages.zero? || last_page?),
|
31
|
-
last: (links_pagination.expand(offset: total_pages, limit: limit_value).to_s unless total_pages.zero? || last_page?)
|
32
|
-
}.compact
|
33
|
-
else
|
34
|
-
{}
|
35
|
-
end,
|
36
|
-
data: resources,
|
37
|
-
included:
|
38
|
-
}.transform_values(&:presence).compact
|
25
|
+
links: pagination,
|
26
|
+
included:,
|
27
|
+
meta:
|
28
|
+
}.transform_values(&:presence).compact.merge(data: resources)
|
39
29
|
end
|
40
30
|
|
41
31
|
private def materializers
|
42
32
|
@materializers ||= object.map { |subobject| self.class.module_parent.new(object: subobject, selects:, includes:) }
|
43
33
|
end
|
44
34
|
|
45
|
-
private def links_pagination
|
46
|
-
Addressable::Template.new(
|
47
|
-
"#{origin}/#{type}?page[offset]={offset}&page[limit]={limit}"
|
48
|
-
)
|
49
|
-
end
|
50
|
-
|
51
|
-
private def links_self
|
52
|
-
Addressable::Template.new(
|
53
|
-
"#{origin}/#{type}"
|
54
|
-
).pattern
|
55
|
-
end
|
56
|
-
|
57
35
|
private def origin
|
58
36
|
self.class.module_parent.instance_variable_get(:@origin)
|
59
37
|
end
|
@@ -74,6 +52,36 @@ module JSONAPI
|
|
74
52
|
@includes || []
|
75
53
|
end
|
76
54
|
|
55
|
+
private def pagination
|
56
|
+
if @pagination
|
57
|
+
{
|
58
|
+
first: (pagination_link_template.expand(offset: 1, limit: limit_value).to_s unless total_pages.zero? || first_page?),
|
59
|
+
prev: (pagination_link_template.expand(offset: prev_page, limit: limit_value).to_s unless total_pages.zero? || first_page?),
|
60
|
+
self: (self_link_template unless total_pages.zero?),
|
61
|
+
next: (pagination_link_template.expand(offset: next_page, limit: limit_value).to_s unless total_pages.zero? || last_page?),
|
62
|
+
last: (pagination_link_template.expand(offset: total_pages, limit: limit_value).to_s unless total_pages.zero? || last_page?)
|
63
|
+
}.compact
|
64
|
+
else
|
65
|
+
{}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
private def pagination_link_template
|
70
|
+
Addressable::Template.new(
|
71
|
+
"#{origin}/#{type}?page[offset]={offset}&page[limit]={limit}"
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
private def self_link_template
|
76
|
+
Addressable::Template.new(
|
77
|
+
"#{origin}/#{type}"
|
78
|
+
).pattern
|
79
|
+
end
|
80
|
+
|
81
|
+
private def meta
|
82
|
+
{}
|
83
|
+
end
|
84
|
+
|
77
85
|
private def included
|
78
86
|
@included ||= materializers.flat_map do |materializer|
|
79
87
|
includes.flat_map do |path|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-materializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kurtis Rainbolt-Greene
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|