simple-json-api-serializer 0.2.0 → 0.3.0
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/Gemfile.lock +2 -2
- data/lib/json_api/object_serializer.rb +5 -1
- data/lib/json_api/object_serializer_definition.rb +15 -4
- data/lib/json_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ba77670aea7fe65f45dd044dd16de898d538b57
|
4
|
+
data.tar.gz: 6b3e6626f0a06154cfe61d992f63cd932593860f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 203f943f6ba18beb7b1a79a27b4507251f811aeca62bf2b1bc03fa1f30ead13ace20544ee051d502f7f6712649fb293b7b2d3e1235cd8c10da933270aad813a4
|
7
|
+
data.tar.gz: 9f8f084339a487a9c3cfb3a64861b333461d21c31386017700e796b1854599db992a4f2c8f1f7e1a9eb57cfeef05ba1dba74e66a879dff34a73a17f0987a1265
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simple-json-api-serializer (0.
|
4
|
+
simple-json-api-serializer (0.3.0)
|
5
5
|
activesupport (~> 4.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (4.2.
|
10
|
+
activesupport (4.2.3)
|
11
11
|
i18n (~> 0.7)
|
12
12
|
json (~> 1.7, >= 1.7.7)
|
13
13
|
minitest (~> 5.1)
|
@@ -6,13 +6,17 @@ require 'json_api/relationship_serializer'
|
|
6
6
|
module JSONApi
|
7
7
|
class ObjectSerializer
|
8
8
|
def serialize(object, **options)
|
9
|
+
ActiveSupport::JSON.encode(hashify(object, **options))
|
10
|
+
end
|
11
|
+
|
12
|
+
def hashify(object, **options)
|
9
13
|
hash = { data: data_for(object, **options) }
|
10
14
|
|
11
15
|
if options[:include].is_a?(Array)
|
12
16
|
hash[:included] = options[:include]
|
13
17
|
end
|
14
18
|
|
15
|
-
|
19
|
+
hash
|
16
20
|
end
|
17
21
|
|
18
22
|
private
|
@@ -4,13 +4,15 @@ module JSONApi
|
|
4
4
|
class ObjectSerializerDefinition
|
5
5
|
class << self
|
6
6
|
def serialize(object, **options)
|
7
|
-
options
|
8
|
-
options[:attributes] ||= attributes
|
9
|
-
options[:relationships] ||= relationships
|
10
|
-
|
7
|
+
options = merge_options(**options)
|
11
8
|
ObjectSerializer.new.serialize(object, **options)
|
12
9
|
end
|
13
10
|
|
11
|
+
def hashify(object, **options)
|
12
|
+
options = merge_options(**options)
|
13
|
+
ObjectSerializer.new.hashify(object, **options)
|
14
|
+
end
|
15
|
+
|
14
16
|
def inherited(specialization)
|
15
17
|
specialization.attributes(*attributes)
|
16
18
|
specialization.relationships(*relationships)
|
@@ -45,6 +47,15 @@ module JSONApi
|
|
45
47
|
config[:to] = :many
|
46
48
|
relationship(name, config)
|
47
49
|
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def merge_options(**options)
|
54
|
+
options[:id_attribute] ||= id_attribute
|
55
|
+
options[:attributes] ||= attributes
|
56
|
+
options[:relationships] ||= relationships
|
57
|
+
options
|
58
|
+
end
|
48
59
|
end
|
49
60
|
end
|
50
61
|
end
|
data/lib/json_api/version.rb
CHANGED