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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f8a25629577c83f71a66b2451f2858cad759e9ace5547e8f9add4eb11be8771
4
- data.tar.gz: 978d36a75ebdb775b86698afd5f8f7659dc64b9d993b2046f45aaf979ca52549
3
+ metadata.gz: ed6ae5d478596b65ee33d68c10862a87f351dd7711e49e9ac7b15237e878fbea
4
+ data.tar.gz: 33ed98e503065a2d5dfe21f4e6e551d3c6ba30dfcf052d0e621bf5d9750519be
5
5
  SHA512:
6
- metadata.gz: 6aff817c68c5d0795389456eafe32aa791f0dd45a3998bb8101a443dc7681b5aaaa719a0de4694c4af001eec98b66b81fffc24f4ed874d089e1951a1ae3d42b6
7
- data.tar.gz: 362d898e479fe85e629abf911e034d4c56236ef95e21b1000f2c839a12fc8d87b028f765bba661856c65bd77020e8f557ee29780df071a644829e26ea2e3d080
6
+ metadata.gz: ee6ff44d1b2318451073b38d38db1e015edf19d7df70c61f5e15406ff00483eeb7d0d131173fa61e233c8cf782d3a0345f12fdf9bcea31187a10a2143585a9b7
7
+ data.tar.gz: 4afd04abcd28e6a8792c8f947ad97473a452fe792e3ed4e1bac6d2e99f7fe4cfb5b614d7589d2e2d10dcd3684285c75a8510bf061d73cfcac976519ea02eaa66
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Chronicle
4
4
  module Core
5
- VERSION = "0.2.1"
5
+ VERSION = "0.2.2"
6
6
  end
7
7
  end
@@ -1,4 +1,4 @@
1
- require 'chronicle/utils/hash'
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::Hash.flatten_keys(to_h)
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.1
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 00:00:00.000000000 Z
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/hash.rb
129
+ - lib/chronicle/utils/hash_utils.rb
130
130
  - sig/chronicle/core.rbs
131
131
  homepage: https://github.com/chronicle-app
132
132
  licenses:
@@ -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