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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/simple_serializer.rb +9 -5
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b16bb9cbab2643eb539ea0e1dd1ea4a99dcee623e28a5147d1ea91febd1d3e54
4
- data.tar.gz: 673c7795f0c85abb4d0a3802bdfc8a20d0c4d4d2c86775397a49843abf75e00d
3
+ metadata.gz: af1cf7cdbe385436458da4107ae3989ba4ab22d1019cedce0581bf52efffd8f2
4
+ data.tar.gz: da81b736cf7330063be2039b58aebc6bcb5574cf2cf6220fb8a126a4d46dbe9a
5
5
  SHA512:
6
- metadata.gz: b5d36e897bbe0256cb91693ff5863b870fb2a2b9c2dacfba496b6119e34e9f982fd397aea037beb8ba749f34ae8812fc1c684ea5315a0ae8a1c6597f58c445fa
7
- data.tar.gz: 6e936d6b429421b8c9e53b93fad589ba87ff8218dd29cf8e3c946691c83a1dba95962cc2cf9844f17db92842c4cdb8d29eff9afa981891c43f3d0ea54054dc47
6
+ metadata.gz: 6ef2496dde184050de2ecb11f2231b3cd735389f6fb6212cf6260cc35ce5407e7450a8b434ef6efa0ec2cf6790b91f374158132e2bffd0234dc300df87441711
7
+ data.tar.gz: 4d28f19efd27d8d689eaffe8f22e0dc52d1e5d4ec87248fe74d9d19098d5fec52ee65e2febc62db9aafcb5b2921b61d57cf8ffa3a99bed29c9c817020bc89d61
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class SimpleSerializer
4
- VERSION = '0.1.4'
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
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-02-14 00:00:00.000000000 Z
11
+ date: 2020-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec