typelizer 0.5.5 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b353423e2bc10fd89e3d944692c04b41b69f6b75567821060b5b9e84b5009a0
4
- data.tar.gz: 6abb793e276d1a6627284ac7e3e5a37888e9d48850f0f74c3475ee5034c06d11
3
+ metadata.gz: f1c1d02eab4c7f1ea170ecd4b855fa37952273faa3223333cd6f6f2020dad397
4
+ data.tar.gz: 519c348552314735af8c1ba5072a8cd7cbb492b822d0bf5564b95b965f42ff12
5
5
  SHA512:
6
- metadata.gz: 92ebe7361f52e8644576b8eabffcf0602f24369e9f6a9bc82837550b123440438befef9fb0d730c8c96cab63e111858aa05088b65aa46ab2a1c6b2c58868fcff
7
- data.tar.gz: 9ee89e0e1761257e51a97ba4666c3cecc4c02581f1726117f67f5328be510b4fd05653f46effad3d33fb119dcee01c9734160be3b2893d3cf566a2d5079c05f5
6
+ metadata.gz: e5d72c98f8ac58bba2a48673ec3f54e86e6aba2d25168312433d5288461aef7c1fd5d0d65aa2137759f03831c432aee5d9a2f5fc626068d302d295749d1f9ca7
7
+ data.tar.gz: 4134b806f9f788a32920dfb6ae8980b66083c7b22b897be3f3d005915fd5e444712fe12535a409c47c6d5cee4158f91696c11df7692f2ced26361bc169cd91d3
data/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning].
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.5.6] - 2026-01-12
11
+
12
+ ### Added
13
+
14
+ - Type inference for serialized fields. `serialize :skills, type: Array` generates `Array<unknown>`, `serialize :settings, type: Hash` generates `Record<string, unknown>`. ([@skryukov])
15
+
16
+ ### Fixed
17
+
18
+ - Alba: respect `key:` option for associations defined in traits. ([@skryukov])
19
+
10
20
  ## [0.5.5] - 2025-12-24
11
21
 
12
22
  ### Added
@@ -310,7 +320,8 @@ and this project adheres to [Semantic Versioning].
310
320
  [@prog-supdex]: https://github.com/prog-supdex
311
321
  [@ventsislaf]: https://github.com/ventsislaf
312
322
 
313
- [Unreleased]: https://github.com/skryukov/typelizer/compare/v0.5.5...HEAD
323
+ [Unreleased]: https://github.com/skryukov/typelizer/compare/v0.5.6...HEAD
324
+ [0.5.6]: https://github.com/skryukov/typelizer/compare/v0.5.5...v0.5.6
314
325
  [0.5.5]: https://github.com/skryukov/typelizer/compare/v0.5.4...v0.5.5
315
326
  [0.5.4]: https://github.com/skryukov/typelizer/compare/v0.5.3...v0.5.4
316
327
  [0.5.3]: https://github.com/skryukov/typelizer/compare/v0.5.2...v0.5.3
@@ -104,6 +104,10 @@ module Typelizer
104
104
  attribute_type_obj = model_class.attribute_types.fetch(prop.column_name.to_s, nil)
105
105
  return nil unless attribute_type_obj
106
106
 
107
+ if attribute_type_obj.instance_of?(::ActiveRecord::Type::Serialized)
108
+ return infer_types_for_serialized(prop, attribute_type_obj)
109
+ end
110
+
107
111
  if attribute_type_obj.respond_to?(:subtype)
108
112
  prop.type = @config.type_mapping[attribute_type_obj.subtype.type]
109
113
  prop.multi = true
@@ -113,6 +117,23 @@ module Typelizer
113
117
 
114
118
  prop
115
119
  end
120
+
121
+ def infer_types_for_serialized(prop, type_obj)
122
+ object_class = type_obj.coder.try(:object_class) ||
123
+ type_obj.try(:object_class)
124
+
125
+ case object_class&.to_s
126
+ when "Array"
127
+ prop.type = :unknown
128
+ prop.multi = true
129
+ when "Hash"
130
+ prop.type = "Record<string, unknown>"
131
+ else
132
+ prop.type = :unknown
133
+ end
134
+
135
+ prop
136
+ end
116
137
  end
117
138
  end
118
139
  end
@@ -54,17 +54,19 @@ module Typelizer
54
54
  end
55
55
 
56
56
  # Simple struct to hold association info from traits
57
- TraitAssociation = Struct.new(:name, :resource, :with_traits, :multi, keyword_init: true)
57
+ TraitAssociation = Struct.new(:name, :resource, :with_traits, :multi, :key, keyword_init: true)
58
58
 
59
59
  # Support association methods that might be used in traits
60
60
  def one(name, **options, &block)
61
61
  resource = options[:resource] || options[:serializer]
62
62
  with_traits = options[:with_traits]
63
- @collected_attributes[name] = TraitAssociation.new(
63
+ key = options[:key] || name
64
+ @collected_attributes[key] = TraitAssociation.new(
64
65
  name: name,
65
66
  resource: resource,
66
67
  with_traits: with_traits,
67
- multi: false
68
+ multi: false,
69
+ key: key
68
70
  )
69
71
  end
70
72
 
@@ -74,11 +76,13 @@ module Typelizer
74
76
  def many(name, **options, &block)
75
77
  resource = options[:resource] || options[:serializer]
76
78
  with_traits = options[:with_traits]
77
- @collected_attributes[name] = TraitAssociation.new(
79
+ key = options[:key] || name
80
+ @collected_attributes[key] = TraitAssociation.new(
78
81
  name: name,
79
82
  resource: resource,
80
83
  with_traits: with_traits,
81
- multi: true
84
+ multi: true,
85
+ key: key
82
86
  )
83
87
  end
84
88
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Typelizer
4
- VERSION = "0.5.5"
4
+ VERSION = "0.5.6"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typelizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Svyatoslav Kryukov