waveguide 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/lib/waveguide/serializer.rb +16 -12
- data/lib/waveguide/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 163022ccfce122fddc992b3b9ae47fb5ae592a2c
|
4
|
+
data.tar.gz: e223abb6070f4ab88b93eee195e40d6992880bdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e2e15688e74dec7df83a7d68566ab13a7bb4d662ec3504b232674af0e38f6516d78d288c4818bd68f4f05362f7f2d9175308ce4055c8a30fb1f155da233e4a3
|
7
|
+
data.tar.gz: f27c232cd99c38239537aeeaa6475cd52e6adce91fd5563782eb992bcdb4b887f482a49c8106e40284b4f5604296a322b14b82e7e8d396bc5db5276a2b87087c
|
data/lib/waveguide/serializer.rb
CHANGED
@@ -17,11 +17,11 @@ module Waveguide
|
|
17
17
|
|
18
18
|
self.class.attributes_to_serialize.each do |key|
|
19
19
|
output[key] = self.send(key)
|
20
|
-
end
|
20
|
+
end
|
21
21
|
|
22
22
|
self.class.conditional_attributes.each do |key|
|
23
23
|
output[key] = self.send(key) if self.send("include_#{key}?")
|
24
|
-
end
|
24
|
+
end
|
25
25
|
|
26
26
|
output
|
27
27
|
end
|
@@ -34,9 +34,9 @@ module Waveguide
|
|
34
34
|
|
35
35
|
def inherited(base)
|
36
36
|
super
|
37
|
-
base.attributes_to_serialize = attributes_to_serialize
|
38
|
-
base.conditional_attributes = conditional_attributes
|
39
|
-
base.serializer_methods = serializer_methods
|
37
|
+
base.attributes_to_serialize = (attributes_to_serialize || []).dup
|
38
|
+
base.conditional_attributes = (conditional_attributes || []).dup
|
39
|
+
base.serializer_methods = (serializer_methods || {}).dup
|
40
40
|
|
41
41
|
(self.serializer_methods || {}).each do |key, block|
|
42
42
|
base.send(:define_method, key, &block)
|
@@ -82,20 +82,24 @@ module Waveguide
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
def has_one(relation_name, as: nil, serializer:)
|
85
|
+
def has_one(relation_name, as: nil, serializer: nil)
|
86
86
|
key = as || relation_name
|
87
87
|
add_attribute(key)
|
88
|
-
|
89
|
-
|
88
|
+
if serializer
|
89
|
+
define_serializer_method(key) do
|
90
|
+
serializer.new(object.send(relation_name), scope).as_json
|
91
|
+
end
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
93
|
-
def has_many(relation_name, as: nil, serializer:)
|
95
|
+
def has_many(relation_name, as: nil, serializer: nil)
|
94
96
|
key = as || relation_name
|
95
97
|
add_attribute(key)
|
96
|
-
|
97
|
-
|
98
|
-
|
98
|
+
if serializer
|
99
|
+
define_serializer_method(key) do
|
100
|
+
object.send(relation_name).map do |item|
|
101
|
+
serializer.new(item, scope).as_json
|
102
|
+
end
|
99
103
|
end
|
100
104
|
end
|
101
105
|
end
|
data/lib/waveguide/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: waveguide
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Gough
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
137
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.6.
|
138
|
+
rubygems_version: 2.6.14
|
139
139
|
signing_key:
|
140
140
|
specification_version: 4
|
141
141
|
summary: A fast serialization library for Ruby.
|