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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aaf1df730a3a2162e2d191d8da4b49de7697ff7ef4809f986cf4e99d837b4a3b
4
- data.tar.gz: 5baafec6c85e5f380a74abf920d7b1a22cde35d6f1e4d00c803bbe4370767b8e
3
+ metadata.gz: e462c6e45374dd57c9f5f917f27fd9663aac1d0b3e52bca7cf0f7f7e0f7678d1
4
+ data.tar.gz: cde0c817337276215b02fa6a60c5418d1f77b8c063898da37e6420d83eb2891a
5
5
  SHA512:
6
- metadata.gz: 55ba3bfb9406b4850851bf233076a99426b809c56455c1621d6c122c1d6bdd44680451af8eea8a7f7f82ed2814d661529d8b018ab98354f68154f81387f6eaea
7
- data.tar.gz: 4dd22697d9105583e7474208d33ecb847c81ff0b803db59fe08fc225267149f9723cbd777d4acadfa8590cf2564dc87103d7d7a4f2ffb5bde2712212870517cf
6
+ metadata.gz: d4cc1628d08186773cf267b1a56c60e103c12bdd971e290c208eb4bbcfadee7b838ce132a44c9d552f8d16cbf5fae20d5c8f5aabacbd7f5d5061a42b8a4c5a3b
7
+ data.tar.gz: 60b384baf07c164ccef70630abcfffb88ff09efcd44befd32bfbe3644793a8abad4982aa4a25617c41f4ca61bd668445b5e885b4b37fa37582721df6ca4e6b4c
data/README.md CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
  ## Usage
22
22
 
23
23
  ```ruby
24
- class OrderSerializer < Primalize::JSONAPI
24
+ class OrderSerializer < Primalize::JSONAPI[Order]
25
25
  # Notice we no longer need the `id` field. It is assumed.
26
26
  attributes(
27
27
  customer_name: string,
@@ -1,5 +1,5 @@
1
1
  module Primalize
2
2
  module JSONAPI
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
@@ -119,8 +119,31 @@ module Primalize
119
119
  end
120
120
  end
121
121
 
122
- def self.[] *args
123
- Class.new(Single) do
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: primalize-jsonapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Gaskins