simple_serializer 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +5 -5
- data/lib/simple_serializer.rb +3 -0
- data/lib/simple_serializer/deserializer.rb +32 -32
- data/lib/simple_serializer/version.rb +1 -1
- data/spec/unit/simple_serializer/deserializer_spec.rb +1 -1
- data/spec/unit/simple_serializer/serializer_spec.rb +1 -1
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YmE2MmYzZWFlMGRjZWE0MDdmYjYyNGRjYjA3NWUxNzNlZTNhMDU4NA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cc0f2441cc164b6e650204767ed70d42c82a52b5
|
4
|
+
data.tar.gz: 88cf09a21955fdf26ae98a04313125d2effce177
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YjdkOTg2MDUxYTI2MmNkYzNmMDEwNjVhYTMwNzU1OGQzZjRkYmNmZWViYmEw
|
11
|
-
YTJiODMzMDhjMzVlOTQ2NGVlMjVhOWY4MDdhZmEwMDkxOTJiOGU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZmMyZDllMDA5YWM5ZWY0MGEzMDY5OTUyMmNhMmYwMmViZjNmOGI4YWE4ZmNl
|
14
|
-
MmIwZGYxMDIzZWE3MGY0MTMxNjJhNzI4NjNmMTIyNzg4OWViNGNhOGQwNjk1
|
15
|
-
Yzg2ZjJlZGE3Nzk1NjE5ZjFlZDZiYjJmNTQzMGVjOTYwMTk3NmY=
|
6
|
+
metadata.gz: 62d3eb16ae7a44fd9d17da676c3479cdd3cd7ee6fd57eb65321e885dc144f23b8194dab85260c89a7ff1ab637a903aa7c1790cf6ed60b544f5fd0fae6fdc8730
|
7
|
+
data.tar.gz: 28ab46a94b2a0f47de0a03feb4b393d086966ab790b8d404c969a1fd2a2244cd19b6a5094e1b9618c8f3569970ce3bc70318d51c9814c259f0e468aedf87365a
|
data/README.md
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
Simple framelet for serializing/deserializing objects to hashes.
|
4
4
|
|
5
5
|
API compatible with ActiveModel::Serializer but without all the complexity
|
6
|
-
and
|
6
|
+
and NO ROOT KEYS!
|
7
7
|
|
8
8
|
# Serializer Usage
|
9
9
|
|
10
10
|
```
|
11
11
|
class SomeSerializer < SimpleSerializer::Serializer
|
12
|
-
|
12
|
+
hash_attributes :id, :name, :category_id, :errors
|
13
13
|
|
14
14
|
def category_id
|
15
15
|
object.category.try(:id)
|
@@ -34,14 +34,14 @@ SomeSerializer.serialize_array([object])
|
|
34
34
|
|
35
35
|
```
|
36
36
|
class SomeDeserializer < SimpleSerializer::Deserializer
|
37
|
-
|
37
|
+
object_attributes :site_id, :name, :category_id, :integration_key
|
38
38
|
|
39
39
|
def integration_key(old_integration_key)
|
40
40
|
"XX#{@data[:other_attr]}XX#{old_integration_key}XX"
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
44
|
-
object.
|
43
|
+
def set_site_id
|
44
|
+
object.site_id = 99
|
45
45
|
end
|
46
46
|
end
|
47
47
|
```
|
data/lib/simple_serializer.rb
CHANGED
@@ -21,49 +21,49 @@
|
|
21
21
|
# SomeDeserializer.deserialize_array([object1, object2, ...], [data1, data2, ...])
|
22
22
|
#
|
23
23
|
module SimpleSerializer
|
24
|
-
class Deserializer
|
25
|
-
|
26
|
-
|
24
|
+
class Deserializer
|
25
|
+
class << self
|
26
|
+
attr_accessor :_object_attributes
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
def inherited(base)
|
29
|
+
base._object_attributes = []
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
def object_attributes(*attrs)
|
33
|
+
@_object_attributes.concat attrs
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
attrs.each do |attr|
|
36
|
+
define_method attr do
|
37
|
+
@data[attr]
|
38
|
+
end unless method_defined?(attr)
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
define_method "set_#{attr}" do
|
41
|
+
object.send("#{attr}=", send(attr)) if @data.has_key?(attr)
|
42
|
+
end unless method_defined?("set_#{attr}")
|
43
|
+
end
|
43
44
|
end
|
44
|
-
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
def deserialize_array(objects, data)
|
47
|
+
objects.zip(data).map { |obj, datum| deserialize(obj, datum) }
|
48
|
+
end
|
49
49
|
|
50
|
-
|
51
|
-
|
50
|
+
def deserialize(object, data)
|
51
|
+
self.new(object, data).deserialize
|
52
|
+
end
|
52
53
|
end
|
53
|
-
end
|
54
54
|
|
55
|
-
|
55
|
+
attr_reader :object, :data
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
def initialize(object, data)
|
58
|
+
@object = object
|
59
|
+
@data = data
|
60
|
+
end
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
def deserialize
|
63
|
+
self.class._object_attributes.dup.each do |name|
|
64
|
+
send("set_#{name}")
|
65
|
+
end
|
66
|
+
object
|
65
67
|
end
|
66
|
-
object
|
67
68
|
end
|
68
69
|
end
|
69
|
-
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Kirby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.7'
|
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: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: Very simple framelet for serializing/deserializing objects to hashes.
|
@@ -59,7 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- .gitignore
|
62
|
+
- ".gitignore"
|
63
63
|
- Gemfile
|
64
64
|
- LICENSE.txt
|
65
65
|
- README.md
|
@@ -82,17 +82,17 @@ require_paths:
|
|
82
82
|
- lib
|
83
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
|
-
- -
|
85
|
+
- - ">="
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: '0'
|
88
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
|
-
- -
|
90
|
+
- - ">="
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.6.6
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: Very simple framelet for serializing/deserializing objects to hashes.
|