chronicle-core 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chronicle/core/version.rb +1 -1
- data/lib/chronicle/schema/base.rb +18 -3
- data/lib/chronicle/utils/hash_utils.rb +23 -0
- metadata +3 -3
- data/lib/chronicle/utils/hash.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed6ae5d478596b65ee33d68c10862a87f351dd7711e49e9ac7b15237e878fbea
|
4
|
+
data.tar.gz: 33ed98e503065a2d5dfe21f4e6e551d3c6ba30dfcf052d0e621bf5d9750519be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee6ff44d1b2318451073b38d38db1e015edf19d7df70c61f5e15406ff00483eeb7d0d131173fa61e233c8cf782d3a0345f12fdf9bcea31187a10a2143585a9b7
|
7
|
+
data.tar.gz: 4afd04abcd28e6a8792c8f947ad97473a452fe792e3ed4e1bac6d2e99f7fe4cfb5b614d7589d2e2d10dcd3684285c75a8510bf061d73cfcac976519ea02eaa66
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'chronicle/utils/
|
1
|
+
require 'chronicle/utils/hash_utils'
|
2
2
|
|
3
3
|
module Chronicle::Schema
|
4
4
|
class Base
|
@@ -50,11 +50,26 @@ module Chronicle::Schema
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def to_h
|
53
|
-
@properties
|
53
|
+
@properties.transform_values do |v|
|
54
|
+
# convert nested records to hashes
|
55
|
+
if v.is_a?(Array)
|
56
|
+
v.map do |e|
|
57
|
+
if e.is_a?(Chronicle::Schema::Base)
|
58
|
+
e.to_h
|
59
|
+
else
|
60
|
+
e
|
61
|
+
end
|
62
|
+
end
|
63
|
+
elsif v.is_a?(Chronicle::Schema::Base)
|
64
|
+
v.to_h
|
65
|
+
else
|
66
|
+
v
|
67
|
+
end
|
68
|
+
end
|
54
69
|
end
|
55
70
|
|
56
71
|
def to_h_flattened
|
57
|
-
Chronicle::Utils::
|
72
|
+
Chronicle::Utils::HashUtils.flatten_hash(to_h)
|
58
73
|
end
|
59
74
|
end
|
60
75
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Chronicle::Utils
|
2
|
+
module HashUtils
|
3
|
+
def self.flatten_hash(hash, parent_key = '', result = {})
|
4
|
+
hash.each do |key, value|
|
5
|
+
current_key = parent_key + (parent_key.empty? ? '' : '.') + key.to_s
|
6
|
+
if value.is_a?(Hash)
|
7
|
+
flatten_hash(value, current_key, result)
|
8
|
+
elsif value.is_a?(Array)
|
9
|
+
value.each_with_index do |item, index|
|
10
|
+
if item.is_a?(Hash)
|
11
|
+
flatten_hash(item, "#{current_key}[#{index}]", result)
|
12
|
+
else
|
13
|
+
result["#{current_key}[#{index}]".to_sym] = item
|
14
|
+
end
|
15
|
+
end
|
16
|
+
else
|
17
|
+
result[current_key.to_sym] = value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
result
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chronicle-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Louis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-schema
|
@@ -126,7 +126,7 @@ files:
|
|
126
126
|
- lib/chronicle/serialization/hash_serializer.rb
|
127
127
|
- lib/chronicle/serialization/jsonapi_serializer.rb
|
128
128
|
- lib/chronicle/serialization/serializer.rb
|
129
|
-
- lib/chronicle/utils/
|
129
|
+
- lib/chronicle/utils/hash_utils.rb
|
130
130
|
- sig/chronicle/core.rbs
|
131
131
|
homepage: https://github.com/chronicle-app
|
132
132
|
licenses:
|
data/lib/chronicle/utils/hash.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module Chronicle::Utils
|
2
|
-
module Hash
|
3
|
-
def self.flatten_keys(hash)
|
4
|
-
hash.each_with_object({}) do |(k, v), h|
|
5
|
-
if v.is_a? Hash
|
6
|
-
flatten_hash(v).map do |h_k, h_v|
|
7
|
-
h["#{k}.#{h_k}".to_sym] = h_v
|
8
|
-
end
|
9
|
-
else
|
10
|
-
h[k] = v
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|