typelizer 0.9.2 → 0.9.3

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: 505210c62639d70e95336cfb02bb0ab952089ac8433d5816774977853af264a1
4
- data.tar.gz: 2878868d86acf4da05caaf5e139e3ccacf58025b8bf5fc2bc56c04b0a91049b4
3
+ metadata.gz: 9e0f1018fd5d37ab4171501db8961c7895e796f1f41bf292c773f6d39fa08832
4
+ data.tar.gz: 3ab825f73e774cb8d13bb61772c878501e25b42f7e1b3ad35ae2a7a6a31e2d32
5
5
  SHA512:
6
- metadata.gz: b1522f196e8372d77e253bba7f9515043f925aa0f4d8ac6c3b1a11b837424743bba3225774b9dbd65232e46befdabbcb440ef6cf3370edc61e9dece9bf204e2e
7
- data.tar.gz: 6e8acdb494ec3f5167bbfe9f53422ebd26d4e9d8dab89ec832518b1acda47aae821a002dd954daa7605f273f323092e3622699dffad88805120dbf3d3ad2fa4e
6
+ metadata.gz: 31b6a138ee7ae3c95f173f2df1f2168469b285aeff266c350c27a95b51021fa2deeb43bea1f9b28a0f9a4114a6ff4af9f82e47e64f04dcf314c88dfa9d042936
7
+ data.tar.gz: ccd0cb33a718fedae63e46e83bc7495d6b3520d7bfe6b190e2021e98f0f986ed36ca970dd25a71acbcc9017fd1b4b7579fb2399cf6727c92c2a13a1f38d84d80
data/CHANGELOG.md CHANGED
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning].
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.9.3] - 2026-02-27
11
+
12
+ ### Fixed
13
+
14
+ - Fix keyless `typelize` DSL without name. ([@skryukov])
15
+ - Support arrays for keyless `typelize` calls. ([@skryukov])
16
+
10
17
  ## [0.9.2] - 2026-02-26
11
18
 
12
19
  ### Fixed
@@ -426,7 +433,8 @@ and this project adheres to [Semantic Versioning].
426
433
  [@skryukov]: https://github.com/skryukov
427
434
  [@ventsislaf]: https://github.com/ventsislaf
428
435
 
429
- [Unreleased]: https://github.com/skryukov/typelizer/compare/v0.9.2...HEAD
436
+ [Unreleased]: https://github.com/skryukov/typelizer/compare/v0.9.3...HEAD
437
+ [0.9.3]: https://github.com/skryukov/typelizer/compare/v0.9.2...v0.9.3
430
438
  [0.9.2]: https://github.com/skryukov/typelizer/compare/v0.9.1...v0.9.2
431
439
  [0.9.1]: https://github.com/skryukov/typelizer/compare/v0.9.0...v0.9.1
432
440
  [0.9.0]: https://github.com/skryukov/typelizer/compare/v0.8.0...v0.9.0
@@ -29,7 +29,7 @@ module Typelizer
29
29
  return unless keyless_type
30
30
 
31
31
  type, attrs = keyless_type
32
- typelize(name => [type, attrs])
32
+ store_type(:_typelizer_attributes, name, attrs.merge(type: type))
33
33
  self.keyless_type = nil
34
34
  end
35
35
 
data/lib/typelizer/dsl.rb CHANGED
@@ -73,11 +73,26 @@ module Typelizer
73
73
  assign_type_information(:_typelizer_meta_attributes, attributes)
74
74
  end
75
75
 
76
+ def store_type(attribute_name, name, options)
77
+ ensure_type_store(attribute_name)
78
+ instance_variable_get("@#{attribute_name}")[name.to_sym] ||= {}
79
+ instance_variable_get("@#{attribute_name}")[name.to_sym].merge!(options)
80
+ end
81
+
76
82
  private
77
83
 
78
84
  def assign_type_information(attribute_name, attributes)
79
85
  return unless Typelizer.enabled?
80
86
 
87
+ attributes.each do |name, attrs|
88
+ next unless name
89
+
90
+ options = parse_type_declaration(attrs)
91
+ store_type(attribute_name, name, options)
92
+ end
93
+ end
94
+
95
+ def ensure_type_store(attribute_name)
81
96
  instance_variable = "@#{attribute_name}"
82
97
 
83
98
  unless instance_variable_get(instance_variable)
@@ -96,29 +111,26 @@ module Typelizer
96
111
  end
97
112
  end
98
113
  end
114
+ end
99
115
 
100
- attributes.each do |name, attrs|
101
- next unless name
102
-
103
- attrs = [attrs] if attrs && !attrs.is_a?(Array)
104
- options = attrs.last.is_a?(Hash) ? attrs.pop : {}
105
-
106
- if attrs.any?
107
- parsed_types = attrs.map { |t| TypeParser.parse(t) }
108
- all_types = parsed_types.flat_map { |p| Array(p[:type]) }
109
- parsed_types.each do |parsed|
110
- options[:optional] = true if parsed[:optional]
111
- options[:multi] = true if parsed[:multi]
112
- options[:nullable] = true if parsed[:nullable]
113
- end
114
- options[:nullable] = true if all_types.delete(:null)
115
- # Unwrap single-element arrays: typelize field: ["string"] behaves like typelize field: "string"
116
- options[:type] = (all_types.size == 1) ? all_types.first : all_types
116
+ def parse_type_declaration(attrs)
117
+ attrs = [attrs] if attrs && !attrs.is_a?(Array)
118
+ options = attrs.last.is_a?(Hash) ? attrs.pop : {}
119
+
120
+ if attrs.any?
121
+ parsed_types = attrs.map { |t| TypeParser.parse(t) }
122
+ all_types = parsed_types.flat_map { |p| Array(p[:type]) }
123
+ parsed_types.each do |parsed|
124
+ options[:optional] = true if parsed[:optional]
125
+ options[:multi] = true if parsed[:multi]
126
+ options[:nullable] = true if parsed[:nullable]
117
127
  end
118
-
119
- instance_variable_get(instance_variable)[name.to_sym] ||= {}
120
- instance_variable_get(instance_variable)[name.to_sym].merge!(options)
128
+ options[:nullable] = true if all_types.delete(:null)
129
+ # Unwrap single-element arrays: typelize field: ["string"] behaves like typelize field: "string"
130
+ options[:type] = (all_types.size == 1) ? all_types.first : all_types
121
131
  end
132
+
133
+ options
122
134
  end
123
135
  end
124
136
  end
@@ -12,6 +12,7 @@ module Typelizer
12
12
  class << self
13
13
  def parse(type_def, **options)
14
14
  return options if type_def.nil?
15
+ return parse_array(type_def, **options) if type_def.is_a?(Array)
15
16
 
16
17
  type_str = type_def.to_s
17
18
  return parse_union(type_str, **options) if type_str.include?("|")
@@ -39,6 +40,25 @@ module Typelizer
39
40
 
40
41
  private
41
42
 
43
+ def parse_array(type_defs, **options)
44
+ parsed = type_defs.map { |t| parse(t) }
45
+ types = parsed.flat_map { |p| Array(p[:type]) }
46
+
47
+ parsed.each do |p|
48
+ options[:optional] = true if p[:optional]
49
+ options[:multi] = true if p[:multi]
50
+ options[:nullable] = true if p[:nullable]
51
+ end
52
+
53
+ options[:nullable] = true if types.delete(:null)
54
+
55
+ if types.size == 1
56
+ {type: types.first}.merge(options)
57
+ else
58
+ {type: types}.merge(options)
59
+ end
60
+ end
61
+
42
62
  def parse_union(type_str, **options)
43
63
  parts = UnionTypeSorter.split_union_members(type_str)
44
64
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Typelizer
4
- VERSION = "0.9.2"
4
+ VERSION = "0.9.3"
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.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Svyatoslav Kryukov