simple-json-api-serializer 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/lib/json_api.rb +1 -0
- data/lib/json_api/params_deserializer.rb +48 -0
- data/lib/json_api/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5df1c7cd4c2c8c860ec9819d9b746b61ff27d24
|
4
|
+
data.tar.gz: 6000a8133259af0e33f0abc16e702536a8324bcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca12d9d4e3fa0bff22ea271ceadf865e23a99dfd19ced074d4f798fc07e4a7b8dfb7a8b8105539d11d917a3c563094e46bc91f66349a2f034c7fe9abbb9697a9
|
7
|
+
data.tar.gz: c16affcb28eaa535004cb934d0c89fe0f92d88acf039be48f0133ddcf94540cd16f9eda3eb8fdd431f22b4374940acb7a0089f0f1db274bff95e25faaf5aa4d8
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simple-json-api-serializer (0.3.
|
4
|
+
simple-json-api-serializer (0.3.1)
|
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.4)
|
11
11
|
i18n (~> 0.7)
|
12
12
|
json (~> 1.7, >= 1.7.7)
|
13
13
|
minitest (~> 5.1)
|
@@ -16,7 +16,7 @@ GEM
|
|
16
16
|
diff-lcs (1.2.5)
|
17
17
|
i18n (0.7.0)
|
18
18
|
json (1.8.3)
|
19
|
-
minitest (5.8.
|
19
|
+
minitest (5.8.1)
|
20
20
|
rake (10.4.2)
|
21
21
|
rspec (3.3.0)
|
22
22
|
rspec-core (~> 3.3.0)
|
data/lib/json_api.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
module JSONApi
|
2
|
+
class ParamsDeserializer
|
3
|
+
def self.deserialize(data)
|
4
|
+
self.new.deserialize(data)
|
5
|
+
end
|
6
|
+
|
7
|
+
def deserialize(data)
|
8
|
+
type = sanitize_type_name(data.fetch('type'))
|
9
|
+
|
10
|
+
attributes = sanitize_hash(data.fetch('attributes', {}))
|
11
|
+
relationships = data.fetch('relationships', {})
|
12
|
+
|
13
|
+
deserialize_relationships(relationships, attributes)
|
14
|
+
|
15
|
+
{ type => attributes }
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def deserialize_relationships(relationships, attributes)
|
21
|
+
relationships.each do |name, data|
|
22
|
+
data = data.fetch('data')
|
23
|
+
name = sanitize_attribute_name(name)
|
24
|
+
|
25
|
+
attributes["#{name}_id"] = data.fetch('id')
|
26
|
+
attributes["#{name}_type"] = sanitize_type_name(data.fetch('type'))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def sanitize_hash(hash)
|
31
|
+
hash.map do |key, value|
|
32
|
+
value = sanitize_hash(value) if value.is_a?(Hash)
|
33
|
+
[sanitize_attribute_name(key), value]
|
34
|
+
end.to_h
|
35
|
+
end
|
36
|
+
|
37
|
+
def sanitize_attribute_name(attribute_name)
|
38
|
+
attribute_name
|
39
|
+
.downcase
|
40
|
+
.underscore
|
41
|
+
end
|
42
|
+
|
43
|
+
def sanitize_type_name(type_name)
|
44
|
+
sanitize_attribute_name(type_name)
|
45
|
+
.singularize
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/json_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-json-api-serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marten Schilstra
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/json_api.rb
|
88
88
|
- lib/json_api/object_serializer.rb
|
89
89
|
- lib/json_api/object_serializer_definition.rb
|
90
|
+
- lib/json_api/params_deserializer.rb
|
90
91
|
- lib/json_api/relationship_serializer.rb
|
91
92
|
- lib/json_api/utils.rb
|
92
93
|
- lib/json_api/version.rb
|
@@ -111,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
112
|
version: '0'
|
112
113
|
requirements: []
|
113
114
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.4.
|
115
|
+
rubygems_version: 2.4.5.1
|
115
116
|
signing_key:
|
116
117
|
specification_version: 4
|
117
118
|
summary: An extremely simple JSON Api serializer
|