chronicle-core 0.2.0 → 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: 21efb5e6a7bf0dfb29a8e4187dfdfddbac79e47b4a13f636cd7be6e77ff95eea
4
- data.tar.gz: 1527959dfd39a7f4345d784f009d3f5aaf0e67008b31c1734fdf2e1aa0b782db
3
+ metadata.gz: ed6ae5d478596b65ee33d68c10862a87f351dd7711e49e9ac7b15237e878fbea
4
+ data.tar.gz: 33ed98e503065a2d5dfe21f4e6e551d3c6ba30dfcf052d0e621bf5d9750519be
5
5
  SHA512:
6
- metadata.gz: 10caca6156eb0ffac0cbfbc15fbcdf0b1edc289862f74f7dea019bbd57111acccd08d0490f1c893af022ad1337b0b90858f1b54d3b9940f1dca05459c3aced44
7
- data.tar.gz: f780be776364b03063b033e5f39df64eddee82ff6643b0e75fd6840bf9e144742f2f123696163e76d90bee0dc3a33174988f9daaf6ac162e73eed8a5b6861233
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.0"
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,13 +50,26 @@ module Chronicle::Schema
50
50
  end
51
51
 
52
52
  def to_h
53
- identifier_hash
54
- .merge(@properties)
55
- .merge({ meta: meta })
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
56
69
  end
57
70
 
58
71
  def to_h_flattened
59
- Chronicle::Utils::Hash.flatten_keys(to_h)
72
+ Chronicle::Utils::HashUtils.flatten_hash(to_h)
60
73
  end
61
74
  end
62
75
  end
@@ -1,7 +1,15 @@
1
1
  module Chronicle::Serialization
2
2
  class HashSerializer < Chronicle::Serialization::Serializer
3
3
  def serializable_hash
4
- @record.to_h
4
+ @record.properties.transform_values do |v|
5
+ if v.is_a?(Array)
6
+ v.map{|record| HashSerializer.new(record).serializable_hash}
7
+ elsif v.is_a?(Chronicle::Schema::Base)
8
+ HashSerializer.new(v).serializable_hash
9
+ else
10
+ v
11
+ end
12
+ end
5
13
  end
6
14
  end
7
15
  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.0
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