primalize-jsonapi 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/primalize/jsonapi/version.rb +1 -1
- data/lib/primalize/jsonapi.rb +25 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e462c6e45374dd57c9f5f917f27fd9663aac1d0b3e52bca7cf0f7f7e0f7678d1
|
4
|
+
data.tar.gz: cde0c817337276215b02fa6a60c5418d1f77b8c063898da37e6420d83eb2891a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4cc1628d08186773cf267b1a56c60e103c12bdd971e290c208eb4bbcfadee7b838ce132a44c9d552f8d16cbf5fae20d5c8f5aabacbd7f5d5061a42b8a4c5a3b
|
7
|
+
data.tar.gz: 60b384baf07c164ccef70630abcfffb88ff09efcd44befd32bfbe3644793a8abad4982aa4a25617c41f4ca61bd668445b5e885b4b37fa37582721df6ca4e6b4c
|
data/README.md
CHANGED
data/lib/primalize/jsonapi.rb
CHANGED
@@ -119,8 +119,31 @@ module Primalize
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
|
123
|
-
|
122
|
+
@serializer_map = {}
|
123
|
+
|
124
|
+
def self.[]= model_class, serializer
|
125
|
+
@serializer_map[model_class] = serializer
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.[] model_class=nil, **options
|
129
|
+
@serializer_map[model_class] ||= Class.new(Single) do
|
130
|
+
@model_class = model_class
|
131
|
+
|
132
|
+
# This is useful for situations like this:
|
133
|
+
# class MySerializer < Primalize::JSONAPI[MyModel]
|
134
|
+
# end
|
135
|
+
define_singleton_method :inherited do |inheriting_class|
|
136
|
+
JSONAPI[model_class] = inheriting_class
|
137
|
+
end
|
138
|
+
|
139
|
+
def self.model_class
|
140
|
+
if @model_class
|
141
|
+
@model_class
|
142
|
+
else
|
143
|
+
superclass.model_class
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
124
147
|
def self.model_primalizer
|
125
148
|
@model_primalizer ||= Class.new(Single) do
|
126
149
|
def self.attributes **attrs
|