jsonapi.rb 1.5.7 → 1.6.0
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 +5 -5
- data/Gemfile +0 -2
- data/README.md +3 -3
- data/Rakefile +5 -1
- data/jsonapi.rb.gemspec +1 -1
- data/lib/jsonapi/error_serializer.rb +2 -2
- data/lib/jsonapi/rails.rb +24 -7
- data/lib/jsonapi/version.rb +1 -1
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dc1e0239230a7a14a008b6344be8857fccd4db574af564a9b49342842fcc316d
|
4
|
+
data.tar.gz: 16615a0a1e0bd8b6f0a84ae9f2adcc16005a16b6413577b3ee945fddb6ce90c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c65ee96100a9179205b0f8e220f4f42dc5cd0f03fb8c7c645cb1c70933f848e2e0fe11d600259f2001fe1a9d8760b821c4748009ee3451156e2b07a660df783
|
7
|
+
data.tar.gz: 26c49d61c04f3bc03eaee260137905886a421c31d6bb669c063eb4cca9bea15a77327a07e90eb63ede9bb4b0d5e4b153aa38eb6dd6167c2eeabf10a1d7fb8fd6
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -31,7 +31,7 @@ Main goals:
|
|
31
31
|
|
32
32
|
The available features include:
|
33
33
|
|
34
|
-
* object serialization (powered by
|
34
|
+
* object serialization (powered by JSON:API Serializer, was `fast_jsonapi`)
|
35
35
|
* [error handling](https://jsonapi.org/format/#errors) (parameters,
|
36
36
|
validation, generic errors)
|
37
37
|
* fetching of the data (support for
|
@@ -44,7 +44,7 @@ The available features include:
|
|
44
44
|
|
45
45
|
## But how?
|
46
46
|
|
47
|
-
Mainly by leveraging [
|
47
|
+
Mainly by leveraging [JSON:API Serializer](https://github.com/jsonapi-serializer/jsonapi-serializer)
|
48
48
|
and [Ransack](https://github.com/activerecord-hackery/ransack).
|
49
49
|
|
50
50
|
Thanks to everyone who worked on these amazing projects!
|
@@ -100,7 +100,7 @@ The naming scheme follows the `ModuleName::ClassNameSerializer` for an instance
|
|
100
100
|
of the `ModuleName::ClassName`.
|
101
101
|
|
102
102
|
Please follow the
|
103
|
-
[
|
103
|
+
[JSON:API Serializer guide](https://github.com/jsonapi-serializer/jsonapi-serializer#serializer-definition)
|
104
104
|
on how to define a serializer.
|
105
105
|
|
106
106
|
To provide a different naming scheme implement the `jsonapi_serializer_class`
|
data/Rakefile
CHANGED
@@ -24,7 +24,11 @@ RuboCop::RakeTask.new('qa:code') do |task|
|
|
24
24
|
end
|
25
25
|
|
26
26
|
desc('Run CI QA tasks')
|
27
|
-
|
27
|
+
if ENV['RAILS_VERSION'].to_s.include?('4')
|
28
|
+
task(qa: ['qa:docs'])
|
29
|
+
else
|
30
|
+
task(qa: ['qa:docs', 'qa:code'])
|
31
|
+
end
|
28
32
|
|
29
33
|
RSpec::Core::RakeTask.new(spec: :qa)
|
30
34
|
task(default: :spec)
|
data/jsonapi.rb.gemspec
CHANGED
data/lib/jsonapi/rails.rb
CHANGED
@@ -42,8 +42,9 @@ module JSONAPI
|
|
42
42
|
many = JSONAPI::Rails.is_collection?(resource, options[:is_collection])
|
43
43
|
resource = [resource] unless many
|
44
44
|
|
45
|
-
return JSONAPI::
|
46
|
-
.
|
45
|
+
return JSONAPI::Rails.serializer_to_json(
|
46
|
+
JSONAPI::ErrorSerializer.new(resource, options)
|
47
|
+
) unless resource.is_a?(ActiveModel::Errors)
|
47
48
|
|
48
49
|
errors = []
|
49
50
|
model = resource.instance_variable_get('@base')
|
@@ -66,9 +67,11 @@ module JSONAPI
|
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
69
|
-
JSONAPI::
|
70
|
-
|
71
|
-
|
70
|
+
JSONAPI::Rails.serializer_to_json(
|
71
|
+
JSONAPI::ActiveModelErrorSerializer.new(
|
72
|
+
errors, params: { model: model, model_serializer: model_serializer }
|
73
|
+
)
|
74
|
+
)
|
72
75
|
end
|
73
76
|
end
|
74
77
|
|
@@ -100,13 +103,15 @@ module JSONAPI
|
|
100
103
|
serializer_class = JSONAPI::Rails.serializer_class(resource, many)
|
101
104
|
end
|
102
105
|
|
103
|
-
|
106
|
+
JSONAPI::Rails.serializer_to_json(
|
107
|
+
serializer_class.new(resource, options)
|
108
|
+
)
|
104
109
|
end
|
105
110
|
end
|
106
111
|
|
107
112
|
# Checks if an object is a collection
|
108
113
|
#
|
109
|
-
# Stolen from [
|
114
|
+
# Stolen from [JSONAPI::Serializer], instance method.
|
110
115
|
#
|
111
116
|
# @param resource [Object] to check
|
112
117
|
# @param force_is_collection [NilClass] flag to overwrite
|
@@ -126,5 +131,17 @@ module JSONAPI
|
|
126
131
|
|
127
132
|
"#{klass.name}Serializer".constantize
|
128
133
|
end
|
134
|
+
|
135
|
+
# Lazily returns the serializer JSON
|
136
|
+
#
|
137
|
+
# @param serializer [Object] to evaluate
|
138
|
+
# @return [String]
|
139
|
+
def self.serializer_to_json(serializer)
|
140
|
+
if serializer.respond_to?(:serialized_json)
|
141
|
+
serializer.serialized_json
|
142
|
+
else
|
143
|
+
serializer.serializable_hash.to_json
|
144
|
+
end
|
145
|
+
end
|
129
146
|
end
|
130
147
|
end
|
data/lib/jsonapi/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stas Suscov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: jsonapi-serializer
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: ransack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -269,8 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
269
269
|
- !ruby/object:Gem::Version
|
270
270
|
version: '0'
|
271
271
|
requirements: []
|
272
|
-
|
273
|
-
rubygems_version: 2.5.2.2
|
272
|
+
rubygems_version: 3.1.2
|
274
273
|
signing_key:
|
275
274
|
specification_version: 4
|
276
275
|
summary: So you say you need JSON:API support in your API...
|