jsonapi-renderer 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/lib/jsonapi/include_directive.rb +15 -0
- data/lib/jsonapi/renderer/cached_resources_processor.rb +6 -1
- data/lib/jsonapi/renderer/document.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ebb3c77141d2eab3df3c86e6801b1566d940a7355a8018fa6682f06dfa184a94
|
4
|
+
data.tar.gz: bc4eea2b4d56daccd7d27feefb354e674a709443a4f504793430821c7bbdbb72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0603897244768c28ad4b1545718f8d46f53e2aeeab4698ec192af4a239b7c56adbe28a000ae81d5210b8b2f69958473bd956ede4142f29c0ede91f3da49ad2b3
|
7
|
+
data.tar.gz: e140f8d78ee9015f099599a69a1e965734d77431c717e9262eedf73b31d1d9339dfa57d89b1ca1e462d8ea318de347a554d0bf22c077ae3c746f87242a7995aa
|
data/README.md
CHANGED
@@ -120,7 +120,7 @@ supporting the `fetch_multi` method.
|
|
120
120
|
When using caching, the serializable resources must implement an
|
121
121
|
additional `jsonapi_cache_key` method:
|
122
122
|
```ruby
|
123
|
-
# Returns a cache key for the resource,
|
123
|
+
# Returns a cache key for the resource, parameterized by the `include` and
|
124
124
|
# `fields` options.
|
125
125
|
# @param options [Hash]
|
126
126
|
# @option fields [Set<Symbol>, Nil] The requested fields, or nil.
|
@@ -16,6 +16,8 @@ module JSONAPI
|
|
16
16
|
def initialize(include_args, options = {})
|
17
17
|
include_hash = Parser.parse_include_args(include_args)
|
18
18
|
@hash = include_hash.each_with_object({}) do |(key, value), hash|
|
19
|
+
raise InvalidKey, key unless valid?(key)
|
20
|
+
|
19
21
|
hash[key] = self.class.new(value, options)
|
20
22
|
end
|
21
23
|
@options = options
|
@@ -68,5 +70,18 @@ module JSONAPI
|
|
68
70
|
|
69
71
|
string_array.join(',')
|
70
72
|
end
|
73
|
+
|
74
|
+
class InvalidKey < StandardError; end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def valid?(key)
|
79
|
+
key.match(valid_json_key_name_regex)
|
80
|
+
end
|
81
|
+
|
82
|
+
def valid_json_key_name_regex
|
83
|
+
# https://jsonapi.org/format/#document-member-names
|
84
|
+
/^(?![\s\-_])[\u0080-\u10FFFFA-Za-z0-9*]+(?<![\s\-_])$/
|
85
|
+
end
|
71
86
|
end
|
72
87
|
end
|
@@ -15,9 +15,14 @@ module JSONAPI
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def process_resources
|
18
|
+
# NOTE(beauby): This is necessary for cache keys consistency.
|
19
|
+
@include_rels = @include_rels.each_with_object({}) do |(k, v), h|
|
20
|
+
h[k] = v.to_a.sort!
|
21
|
+
end
|
22
|
+
|
18
23
|
[@primary, @included].each do |resources|
|
19
24
|
cache_hash = cache_key_map(resources)
|
20
|
-
processed_resources = @cache.fetch_multi(cache_hash.keys) do |key|
|
25
|
+
processed_resources = @cache.fetch_multi(*cache_hash.keys) do |key|
|
21
26
|
res, include, fields = cache_hash[key]
|
22
27
|
json = res.as_jsonapi(include: include, fields: fields).to_json
|
23
28
|
|
@@ -11,7 +11,7 @@ module JSONAPI
|
|
11
11
|
@errors = params.fetch(:errors, [])
|
12
12
|
@meta = params[:meta]
|
13
13
|
@links = params[:links] || {}
|
14
|
-
@fields =
|
14
|
+
@fields = _canonize_fields(params[:fields] || {})
|
15
15
|
@jsonapi = params[:jsonapi]
|
16
16
|
@include = JSONAPI::IncludeDirective.new(params[:include] || {})
|
17
17
|
@relationship = params[:relationship]
|
@@ -91,9 +91,9 @@ module JSONAPI
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
def
|
94
|
+
def _canonize_fields(fields)
|
95
95
|
fields.each_with_object({}) do |(k, v), h|
|
96
|
-
h[k.to_sym] = v.map(&:to_sym)
|
96
|
+
h[k.to_sym] = v.map(&:to_sym).sort!
|
97
97
|
end
|
98
98
|
end
|
99
99
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-renderer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Hosseini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
version: '0'
|
87
87
|
requirements: []
|
88
88
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.
|
89
|
+
rubygems_version: 2.7.8
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
92
|
summary: Render JSONAPI documents.
|