json-serializer 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/json-serializer.gemspec +1 -1
- data/lib/json_serializer.rb +5 -3
- data/test/association.rb +13 -0
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95499fbf4041e6cb01173dcc2b0c242f842010e9
|
4
|
+
data.tar.gz: a54709155b9ea1515c8a2ccf1d1f2ac61c0dba62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 037c0b869e8c2427589b65906130f139f1e54340d5bf11cec27e0ba87acad2d062eaae670c4a6ed4be0275384057e34c856c96101d3c522aeaa02ed2b85ea48b
|
7
|
+
data.tar.gz: 1d6c92842f3f313b0281588afd0b8c13d59cfc39010e6ee3989eb737ee8d8bea6ea0e5fb2e255a3abbf95b7c2c0b8600718f213653d8b3aa45a7c41fc66a2e6f
|
data/json-serializer.gemspec
CHANGED
data/lib/json_serializer.rb
CHANGED
@@ -36,8 +36,10 @@ class JsonSerializer
|
|
36
36
|
protected
|
37
37
|
|
38
38
|
def serializable_object
|
39
|
-
|
40
|
-
|
39
|
+
return nil unless @object
|
40
|
+
|
41
|
+
if @object.respond_to?(:to_a)
|
42
|
+
@object.to_a.map { |item| self.class.new(item).to_hash }
|
41
43
|
else
|
42
44
|
to_hash
|
43
45
|
end
|
@@ -45,7 +47,7 @@ class JsonSerializer
|
|
45
47
|
|
46
48
|
def to_hash
|
47
49
|
self.class.attributes.each_with_object({}) do |(name, serializer), hash|
|
48
|
-
data = self.class.method_defined?(name) ? self.send(name) : object.send(name)
|
50
|
+
data = self.class.method_defined?(name) ? self.send(name) : @object.send(name)
|
49
51
|
data = Utils.const(self.class, serializer).new(data).serializable_object if serializer
|
50
52
|
hash[name] = data
|
51
53
|
end
|
data/test/association.rb
CHANGED
@@ -30,6 +30,19 @@ test "serializes object with association" do
|
|
30
30
|
assert_equal result, UserWithOrganizationSerializer.new(user).to_json
|
31
31
|
end
|
32
32
|
|
33
|
+
test "serializes object with a nil association" do
|
34
|
+
user = User.new(id: 1, name: "sonny")
|
35
|
+
user.organization = nil
|
36
|
+
|
37
|
+
result = {
|
38
|
+
id: 1,
|
39
|
+
name: "sonny",
|
40
|
+
organization: nil
|
41
|
+
}.to_json
|
42
|
+
|
43
|
+
assert_equal result, UserWithOrganizationSerializer.new(user).to_json
|
44
|
+
end
|
45
|
+
|
33
46
|
test "serializes array with association" do
|
34
47
|
users = [
|
35
48
|
User.new(id: 1, name: "sonny", organization: Organization.new(id: 1, name: "enterprise")),
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francesco Rodríguez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cutest
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description: Customize JSON ouput through serializer objects.
|
@@ -31,8 +31,8 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
-
-
|
35
|
-
-
|
34
|
+
- .gems
|
35
|
+
- .gitignore
|
36
36
|
- LICENSE
|
37
37
|
- README.md
|
38
38
|
- json-serializer.gemspec
|
@@ -52,17 +52,17 @@ require_paths:
|
|
52
52
|
- lib
|
53
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
|
-
- -
|
55
|
+
- - '>='
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '0'
|
58
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - '>='
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
requirements: []
|
64
64
|
rubyforge_project:
|
65
|
-
rubygems_version: 2.
|
65
|
+
rubygems_version: 2.0.14
|
66
66
|
signing_key:
|
67
67
|
specification_version: 4
|
68
68
|
summary: Customize JSON ouput through serializer objects.
|