simple-serializer 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_serializer.rb +9 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af1cf7cdbe385436458da4107ae3989ba4ab22d1019cedce0581bf52efffd8f2
|
4
|
+
data.tar.gz: da81b736cf7330063be2039b58aebc6bcb5574cf2cf6220fb8a126a4d46dbe9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ef2496dde184050de2ecb11f2231b3cd735389f6fb6212cf6260cc35ce5407e7450a8b434ef6efa0ec2cf6790b91f374158132e2bffd0234dc300df87441711
|
7
|
+
data.tar.gz: 4d28f19efd27d8d689eaffe8f22e0dc52d1e5d4ec87248fe74d9d19098d5fec52ee65e2febc62db9aafcb5b2921b61d57cf8ffa3a99bed29c9c817020bc89d61
|
data/lib/simple_serializer.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class SimpleSerializer
|
4
|
-
VERSION = '0.1.
|
4
|
+
VERSION = '0.1.5'
|
5
5
|
|
6
|
-
def initialize(object)
|
6
|
+
def initialize(object, opts = {})
|
7
|
+
@include = opts[:include] || []
|
8
|
+
@exclude = opts[:exclude] || []
|
7
9
|
@object = object
|
8
10
|
end
|
9
11
|
|
@@ -38,8 +40,8 @@ class SimpleSerializer
|
|
38
40
|
to_h(object)
|
39
41
|
end
|
40
42
|
|
41
|
-
def to_h(object)
|
42
|
-
new(object).to_h
|
43
|
+
def to_h(object, opts = {})
|
44
|
+
new(object, opts).to_h
|
43
45
|
end
|
44
46
|
|
45
47
|
def to_json(object)
|
@@ -64,7 +66,9 @@ class SimpleSerializer
|
|
64
66
|
private
|
65
67
|
|
66
68
|
def to_h_single(object)
|
67
|
-
self.class.fields&.reduce({}) do |h, (k, v)|
|
69
|
+
self.class.fields&.merge(Hash[@include.zip])&.reduce({}) do |h, (k, v)|
|
70
|
+
next h if @exclude.include?(k)
|
71
|
+
|
68
72
|
h.merge!(serialize_key_val(object, k, v))
|
69
73
|
end
|
70
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikhail Slyusarev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|