structured_params 0.2.0 → 0.5.0

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: 6194009fbc5383add9717e12380cea940598248d52e395acf0abaa6045cea93e
4
- data.tar.gz: 9d5298274672938c883872ef1595d7609d0a13dc8971b395a90efef2c265dbcb
3
+ metadata.gz: '0954531948539d954bd7251dbba7491d65634fa59fb12c034052a37d0139bbbf'
4
+ data.tar.gz: d6f9e25e9f02c62a983d7fa7214a4822dded796f2b3a15fc524c69093df8c8d3
5
5
  SHA512:
6
- metadata.gz: 37c7d0ead65ced25e00fb82d34ebd0b8d6a049ae3ec966a9cb296769fb611c95c0381dbaa8ccdb5aca0c2760296b56a57de6dce030d348d4b88a587fc1cb5b1e
7
- data.tar.gz: 266f140f0d76a90003223e8bb52a6092fa3ce49ca3a9c3eee32881a0f053baee4150802176f6418e13a4ee84bdd884dbe239bdd413061f6f34e7b2a0788685a0
6
+ metadata.gz: 85ada47bdb413cd80d1464d2bc2d149293854b4bd3082a9167d3f165262b47fcbb16c90b5f36e1ccea78a977539891cd4b520533dcb237f4cdffa41eb2165832
7
+ data.tar.gz: f745f4c6b1f6f85a45708cbc7d97770be3493ab60f3fa8097743dbea15cda9acc260d443918abaa26e51ddb1f328acce14a40186aa958eed01e04671d33ac450
data/CHANGELOG.md CHANGED
@@ -1,35 +1,34 @@
1
1
  # Changelog
2
2
 
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [0.1.4] - 2025-09-04
9
-
10
- **Full Changelog**: https://github.com/Syati/structured_params/compare/v0.1.3...v0.1.4
11
-
12
-
13
-
14
- ### Fixed
15
- - Fixed error key consistency issue where `errors.import` was using string keys instead of symbol keys
16
- - Updated method names and comments to use consistent 'structured' terminology instead of 'nested'
17
- - Fixed type annotations for method calls requiring explicit parameters
18
-
19
- ### Changed
20
- - Renamed methods for better consistency:
21
- - `each_nested_attribute_name` `each_structured_attribute_name`
22
- - `validate_nested_parameters` → `validate_structured_parameters`
23
- - `import_nested_errors` → `import_structured_errors`
24
- - `serialize_nested_value` → `serialize_structured_value`
25
- - Updated documentation to reflect current `:object` and `:array` types instead of `:nested`
26
-
27
- ## [0.1.0] - Initial Release
28
-
29
- ### Added
30
- - Initial implementation of StructuredParams with support for structured objects and arrays
31
- - ActiveModel integration for validation and attributes
32
- - Strong Parameters compatibility
33
- - Type system with Object and Array types
34
- - RBS type definitions
35
- - Comprehensive test suite
3
+ ## [0.4.1] - 2025-09-09
4
+
5
+ ## What's Changed
6
+ * Update attributes method signatures to use optional keyword arguments… by @Syati in https://github.com/Syati/structured_params/pull/8
7
+
8
+
9
+ **Full Changelog**: https://github.com/Syati/structured_params/compare/v0.4.0...v0.4.1
10
+
11
+ ## [0.3.0] - 2025-09-06
12
+
13
+ ## What's Changed
14
+ * Expand Rails compatibility to support Rails 7.2+ through 8.x
15
+
16
+ **Full Changelog**: https://github.com/Syati/structured_params/compare/v0.2.0...v0.3.0
17
+
18
+ ## [0.2.0] - 2025-09-05
19
+
20
+ ## What's Changed
21
+ * Improve error handling and serialization features by @Syati in https://github.com/Syati/structured_params/pull/1
22
+
23
+ **Full Changelog**: https://github.com/Syati/structured_params/compare/v0.1.0...v0.2.0
24
+
25
+ ## [0.1.0] - Initial Release
26
+
27
+ ### Added
28
+ - Initial implementation of StructuredParams with support for structured objects and arrays
29
+ - ActiveModel integration for validation and attributes
30
+ - Strong Parameters compatibility
31
+ - Type system with Object and Array types
32
+ - RBS type definitions
33
+ - Comprehensive test suite
34
+
@@ -73,17 +73,26 @@ module StructuredParams
73
73
  end
74
74
 
75
75
  # Convert structured objects to Hash and get attributes
76
- #: (symbolize: true) -> Hash[Symbol, untyped]
77
- #: (symbolize: false) -> Hash[String, untyped]
78
- def attributes(symbolize: false)
76
+ #: (?symbolize: false, ?compact_mode: :none | :nil_only | :all_blank) -> Hash[String, untyped]
77
+ #: (?symbolize: true, ?compact_mode: :none | :nil_only | :all_blank) -> Hash[Symbol, untyped]
78
+ def attributes(symbolize: false, compact_mode: :none)
79
79
  attrs = super()
80
80
 
81
81
  self.class.structured_attributes.each_key do |name|
82
82
  value = attrs[name.to_s]
83
- attrs[name.to_s] = serialize_structured_value(value)
83
+ attrs[name.to_s] = serialize_structured_value(value, compact_mode: compact_mode)
84
84
  end
85
85
 
86
- symbolize ? attrs.deep_symbolize_keys : attrs
86
+ result = symbolize ? attrs.deep_symbolize_keys : attrs
87
+
88
+ case compact_mode
89
+ when :all_blank
90
+ result.compact_blank
91
+ when :nil_only
92
+ result.compact
93
+ else
94
+ result
95
+ end
87
96
  end
88
97
 
89
98
  private
@@ -151,13 +160,22 @@ module StructuredParams
151
160
  end
152
161
 
153
162
  # Serialize structured values
154
- #: (untyped) -> untyped
155
- def serialize_structured_value(value)
163
+ #: (untyped, ?compact_mode: :none | :nil_only | :all_blank) -> untyped
164
+ def serialize_structured_value(value, compact_mode: :none)
156
165
  case value
157
166
  when Array
158
- value.map { |item| item.attributes(symbolize: false) }
167
+ result = value.map { |item| item.attributes(symbolize: false, compact_mode: compact_mode) }
168
+
169
+ case compact_mode
170
+ when :all_blank
171
+ result.compact_blank
172
+ when :nil_only
173
+ result.compact
174
+ else
175
+ result
176
+ end
159
177
  when StructuredParams::Params
160
- value.attributes(symbolize: false)
178
+ value.attributes(symbolize: false, compact_mode: compact_mode)
161
179
  else
162
180
  value
163
181
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module StructuredParams
5
- VERSION = '0.2.0' #: string
5
+ VERSION = '0.5.0' #: string
6
6
  end
@@ -38,10 +38,10 @@ module StructuredParams
38
38
  def errors: () -> ::StructuredParams::Errors
39
39
 
40
40
  # Convert structured objects to Hash and get attributes
41
- # : (symbolize: true) -> Hash[Symbol, untyped]
42
- # : (symbolize: false) -> Hash[String, untyped]
43
- def attributes: (symbolize: true) -> Hash[Symbol, untyped]
44
- | (symbolize: false) -> Hash[String, untyped]
41
+ # : (?symbolize: false, ?compact_mode: :none | :nil_only | :all_blank) -> Hash[String, untyped]
42
+ # : (?symbolize: true, ?compact_mode: :none | :nil_only | :all_blank) -> Hash[Symbol, untyped]
43
+ def attributes: (?symbolize: false, ?compact_mode: :none | :nil_only | :all_blank) -> Hash[String, untyped]
44
+ | (?symbolize: true, ?compact_mode: :none | :nil_only | :all_blank) -> Hash[Symbol, untyped]
45
45
 
46
46
  private
47
47
 
@@ -70,8 +70,8 @@ module StructuredParams
70
70
  def format_error_path: (Symbol, Integer?) -> String
71
71
 
72
72
  # Serialize structured values
73
- # : (untyped) -> untyped
74
- def serialize_structured_value: (untyped) -> untyped
73
+ # : (untyped, ?compact_mode: :none | :nil_only | :all_blank) -> untyped
74
+ def serialize_structured_value: (untyped, ?compact_mode: :none | :nil_only | :all_blank) -> untyped
75
75
 
76
76
  # Integrate structured parameter errors into parent errors
77
77
  # : (untyped, String) -> void
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: structured_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mizuki Yamamoto
@@ -13,30 +13,42 @@ dependencies:
13
13
  name: actionpack
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - "~>"
16
+ - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 8.0.0
18
+ version: '7.2'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '9.0'
19
22
  type: :runtime
20
23
  prerelease: false
21
24
  version_requirements: !ruby/object:Gem::Requirement
22
25
  requirements:
23
- - - "~>"
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '7.2'
29
+ - - "<"
24
30
  - !ruby/object:Gem::Version
25
- version: 8.0.0
31
+ version: '9.0'
26
32
  - !ruby/object:Gem::Dependency
27
33
  name: activemodel
28
34
  requirement: !ruby/object:Gem::Requirement
29
35
  requirements:
30
- - - "~>"
36
+ - - ">="
31
37
  - !ruby/object:Gem::Version
32
- version: 8.0.0
38
+ version: '7.2'
39
+ - - "<"
40
+ - !ruby/object:Gem::Version
41
+ version: '9.0'
33
42
  type: :runtime
34
43
  prerelease: false
35
44
  version_requirements: !ruby/object:Gem::Requirement
36
45
  requirements:
37
- - - "~>"
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '7.2'
49
+ - - "<"
38
50
  - !ruby/object:Gem::Version
39
- version: 8.0.0
51
+ version: '9.0'
40
52
  description: ''
41
53
  email:
42
54
  - mizuki-y@syati.info