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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c675b5a4d39a3b4eb65c74f46d1bb5feb7a62982
4
- data.tar.gz: 27cafb25c01831cfb17ce44cc3d6313164b46fa2
3
+ metadata.gz: 163022ccfce122fddc992b3b9ae47fb5ae592a2c
4
+ data.tar.gz: e223abb6070f4ab88b93eee195e40d6992880bdb
5
5
  SHA512:
6
- metadata.gz: b227c1ac9708194d8d8d38a4cc2a1a07671bd3df6f3b2ad7e94e6d3e382314c0a463055e3e5072ef93e3e2bfcee00e1c4472cccc06bfd1288beac1daccbd4c77
7
- data.tar.gz: 804965333418fe4e705965cc39476eac2d4e9879f3ec1d2673dffbf3d288874b16b5d6b8ba56ce9fa9befe835c94f2b1ba5cc414cf03de62ec2aeaca2e52164e
6
+ metadata.gz: 1e2e15688e74dec7df83a7d68566ab13a7bb4d662ec3504b232674af0e38f6516d78d288c4818bd68f4f05362f7f2d9175308ce4055c8a30fb1f155da233e4a3
7
+ data.tar.gz: f27c232cd99c38239537aeeaa6475cd52e6adce91fd5563782eb992bcdb4b887f482a49c8106e40284b4f5604296a322b14b82e7e8d396bc5db5276a2b87087c
@@ -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.dup || []
38
- base.conditional_attributes = conditional_attributes.dup || []
39
- base.serializer_methods = serializer_methods.dup || {}
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
- define_serializer_method(key) do
89
- serializer.new(object.send(relation_name)).as_json
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
- define_serializer_method(key) do
97
- object.send(relation_name).map do |item|
98
- serializer.new(item).as_json
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
@@ -1,3 +1,3 @@
1
1
  module Waveguide
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
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.10
138
+ rubygems_version: 2.6.14
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: A fast serialization library for Ruby.