serialized-hashie 1.0.3 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40bf8888692d01004a9a62b33fb8831366dd78a190ec725334c96452789ff225
4
- data.tar.gz: 943a6d02c47dfd80ec2fee3807b3118a06af6ca3c44f937828f1289aff19a729
3
+ metadata.gz: 453189d5dcb6f074f9b595cb427c339b44683a047d8226390106f0662ddb92f4
4
+ data.tar.gz: 9e26fa8420bd8817094d51adc6949bf65204bb9dc9fbc73c1934c7c11a772a00
5
5
  SHA512:
6
- metadata.gz: 62ce9e3c24c79b66d1c4e698e6e535f48d9f9f1a0541752d501eda47f8c58b816dcff2513f005f79883448ab27d2324f4eee9256afc50a668d16802d8b1b6772
7
- data.tar.gz: c56bea556cee7327dd8ec55b847cae7455ce12cd6496fc8714feb848cf3c18acd521c1296be978906a559f5717427cd40097b3a2c7af99d8cf9915153bd9cc36
6
+ metadata.gz: 5173fefd9c87a94ec53d182975fe2ae26371aed4efdcfe5168c5e7b5bd826cc3dd2e87985c309b8c0c8bb2093878557212ef0ff3e4fd9582606af0beaf390b3c
7
+ data.tar.gz: c66ac14e0de4f89586891a783424d2ca876a72b3145625eb2ed8065a3bd579d8eb5e2d40a86ef78a1c1b48e3a17ed67ecbb3b1cba448689ff2852d5481ba8d0b
@@ -17,6 +17,9 @@ jobs:
17
17
  with:
18
18
  ruby-version: 2.6.x
19
19
 
20
+ - name: Export version from tag name
21
+ run: echo "${GITHUB_REF/refs\/tags\//}" > VERSION
22
+
20
23
  - name: Build Gem
21
24
  run: gem build *.gemspec
22
25
 
data/.gitignore CHANGED
@@ -13,3 +13,5 @@
13
13
 
14
14
  # rspec failure tracking
15
15
  .rspec_status
16
+ .rubocop-http*
17
+ VERSION
@@ -10,22 +10,13 @@ module SerializedHashie
10
10
  class << self
11
11
 
12
12
  def dump(obj)
13
- obj = obj.reject { |_, v| blank?(v) }
14
- obj.each do |key, value|
15
- if value.is_a?(Array)
16
- obj[key] = value.reject { |v| blank?(v) }
17
- end
18
-
19
- obj[key] = SerializedHashie.dump_extensions.run(obj[key])
20
- end
21
- obj.to_h.to_json
13
+ hash = dump_hash(obj)
14
+ hash.to_json
22
15
  end
23
16
 
24
17
  def load(raw_hash)
25
18
  hash = JSON.parse(presence(raw_hash) || '{}')
26
- hash.each do |key, value|
27
- hash[key] = SerializedHashie.load_extensions.run(value)
28
- end
19
+ hash = load_hash(hash)
29
20
  new(hash)
30
21
  end
31
22
 
@@ -42,6 +33,42 @@ module SerializedHashie
42
33
  blank?(value) ? nil : value
43
34
  end
44
35
 
36
+ def dump_hash(hash)
37
+ hash = hash.transform_values do |value|
38
+ dump_value(value)
39
+ end
40
+ hash.reject { |_, v| blank?(v) }
41
+ end
42
+
43
+ def dump_value(value)
44
+ if blank?(value)
45
+ return nil
46
+ end
47
+
48
+ if value.is_a?(::Hash)
49
+ return dump_hash(value)
50
+ end
51
+
52
+ if value.is_a?(::Array)
53
+ return value.map { |v| dump_value(v) }.compact
54
+ end
55
+
56
+ SerializedHashie.dump_extensions.run(value)
57
+ end
58
+
59
+ def load_hash(hash)
60
+ hash.transform_values do |value|
61
+ load_value(value)
62
+ end
63
+ end
64
+
65
+ def load_value(value)
66
+ return load_hash(value) if value.is_a?(::Hash)
67
+ return value.map { |v| load_value(v) } if value.is_a?(Array)
68
+
69
+ SerializedHashie.load_extensions.run(value)
70
+ end
71
+
45
72
  end
46
73
 
47
74
  end
@@ -2,6 +2,11 @@
2
2
 
3
3
  module SerializedHashie
4
4
 
5
- VERSION = '1.0.3'
5
+ VERSION_FILE_ROOT = File.expand_path('../../VERSION', __dir__)
6
+ if File.file?(VERSION_FILE_ROOT)
7
+ VERSION = File.read(VERSION_FILE_ROOT).strip.delete_prefix('v')
8
+ else
9
+ VERSION = '0.0.0.dev'
10
+ end
6
11
 
7
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serialized-hashie
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-26 00:00:00.000000000 Z
11
+ date: 2020-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal