primalize-jsonapi 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -2
- data/lib/primalize/jsonapi.rb +13 -1
- data/lib/primalize/jsonapi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3350f0fd1aad3c862179c3a156a3d664bcf178d2e03205a67c77c735f9537fd5
|
4
|
+
data.tar.gz: 61448a12418885035336205324c3755a9556d25d60a7f9cfc332b02ab9fcaab2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1066244c0722528c54ac831365f11f9711a8ad9e45102d11e237c0530848b8fb2fddffc1a5da592bf8a86080ebc4829215c3aec71a93c7d798c0172f0aab836e
|
7
|
+
data.tar.gz: 4f9821abd4eb1c960136298faf5a33e88a892a6e54a9b6edfd41e07b827a1ca8413d66736a343b4ae4d9909d7064e35b736afafc3f1bdef6789a2e7707f2b62b
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Primalize::JSONAPI
|
2
2
|
|
3
|
-
This is a JSON-API adapter for the [`primalize` gem](https://github.com/jgaskins/primalize). It aims to provide some level of compatibility with the JSON-API spec while still allowing for the type checking of Primalize.
|
3
|
+
This is a JSON-API adapter for the [`primalize` gem](https://github.com/jgaskins/primalize), which provides type-checked serializers for Ruby web APIs. It aims to provide some level of compatibility with the JSON-API spec while still allowing for the type checking of Primalize.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -40,11 +40,16 @@ class OrderSerializer < Primalize::JSONAPI[Order]
|
|
40
40
|
)
|
41
41
|
|
42
42
|
# Associations are similar to other serialization gems, but you need to
|
43
|
-
# specify the serializer. There is no runtime inference. We do it inside
|
43
|
+
# specify the serializer. There is no runtime inference yet. We do it inside
|
44
44
|
# a block in case it has not been loaded yet.
|
45
45
|
has_many(:line_items) { LineItemSerializer }
|
46
46
|
has_one(:customer) { CustomerSerializer }
|
47
47
|
end
|
48
|
+
```
|
49
|
+
|
50
|
+
## Performance
|
51
|
+
|
52
|
+
Even with type checking, performance is still [over 12x](https://github.com/Netflix/fast_jsonapi/pull/42#issuecomment-364693269) that of `ActiveModel::Serializers`. Netflix's `fast_jsonapi` is faster, but doesn't provide type the type safety of Primalize.
|
48
53
|
|
49
54
|
## Development
|
50
55
|
|
data/lib/primalize/jsonapi.rb
CHANGED
@@ -145,13 +145,25 @@ module Primalize
|
|
145
145
|
end
|
146
146
|
|
147
147
|
def self.model_primalizer
|
148
|
+
original_primalizer = self
|
149
|
+
|
148
150
|
@model_primalizer ||= Class.new(Single) do
|
149
151
|
def self.attributes **attrs
|
150
152
|
attribute_primalizer.attributes attrs
|
151
153
|
end
|
152
154
|
|
153
|
-
|
155
|
+
define_singleton_method :to_s do
|
156
|
+
"#{original_primalizer}.model_primalizer"
|
157
|
+
end
|
158
|
+
define_singleton_method(:name) { to_s }
|
159
|
+
|
160
|
+
define_singleton_method :attribute_primalizer do
|
154
161
|
@attribute_primalizer ||= Class.new(Single) do
|
162
|
+
define_singleton_method :to_s do
|
163
|
+
"#{original_primalizer}.model_primalizer.attribute_primalizer"
|
164
|
+
end
|
165
|
+
|
166
|
+
define_singleton_method(:name) { to_s }
|
155
167
|
end
|
156
168
|
end
|
157
169
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: primalize-jsonapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Gaskins
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: primalize
|