structured_params 0.3.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 +4 -4
- data/CHANGELOG.md +18 -57
- data/lib/structured_params/params.rb +27 -9
- data/lib/structured_params/version.rb +1 -1
- data/sig/structured_params/params.rbs +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0954531948539d954bd7251dbba7491d65634fa59fb12c034052a37d0139bbbf'
|
4
|
+
data.tar.gz: d6f9e25e9f02c62a983d7fa7214a4822dded796f2b3a15fc524c69093df8c8d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85ada47bdb413cd80d1464d2bc2d149293854b4bd3082a9167d3f165262b47fcbb16c90b5f36e1ccea78a977539891cd4b520533dcb237f4cdffa41eb2165832
|
7
|
+
data.tar.gz: f745f4c6b1f6f85a45708cbc7d97770be3493ab60f3fa8097743dbea15cda9acc260d443918abaa26e51ddb1f328acce14a40186aa958eed01e04671d33ac450
|
data/CHANGELOG.md
CHANGED
@@ -1,73 +1,34 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [0.
|
3
|
+
## [0.4.1] - 2025-09-09
|
4
4
|
|
5
5
|
## What's Changed
|
6
|
-
*
|
6
|
+
* Update attributes method signatures to use optional keyword arguments… by @Syati in https://github.com/Syati/structured_params/pull/8
|
7
7
|
|
8
8
|
|
9
|
-
**Full Changelog**: https://github.com/Syati/structured_params/compare/v0.
|
10
|
-
|
11
|
-
## [0.2.1] - 2025-09-06
|
9
|
+
**Full Changelog**: https://github.com/Syati/structured_params/compare/v0.4.0...v0.4.1
|
12
10
|
|
11
|
+
## [0.3.0] - 2025-09-06
|
12
|
+
|
13
13
|
## What's Changed
|
14
|
-
*
|
15
|
-
* Update project documentation by @Syati in https://github.com/Syati/structured_params/pull/3
|
16
|
-
* Add comparison document for StructuredParams and similar gems by @Syati in https://github.com/Syati/structured_params/pull/4
|
17
|
-
* Update Gemfile and CI configuration to support multiple Rails versions by @Syati in https://github.com/Syati/structured_params/pull/5
|
18
|
-
* Refactor release workflow to update version and CHANGELOG handling by @Syati in https://github.com/Syati/structured_params/pull/6
|
14
|
+
* Expand Rails compatibility to support Rails 7.2+ through 8.x
|
19
15
|
|
16
|
+
**Full Changelog**: https://github.com/Syati/structured_params/compare/v0.2.0...v0.3.0
|
20
17
|
|
21
|
-
|
18
|
+
## [0.2.0] - 2025-09-05
|
22
19
|
|
23
20
|
## What's Changed
|
24
|
-
*
|
25
|
-
* Update project documentation by @Syati in https://github.com/Syati/structured_params/pull/3
|
26
|
-
* Add comparison document for StructuredParams and similar gems by @Syati in https://github.com/Syati/structured_params/pull/4
|
27
|
-
* Update Gemfile and CI configuration to support multiple Rails versions by @Syati in https://github.com/Syati/structured_params/pull/5
|
28
|
-
* Refactor release workflow to update version and CHANGELOG handling by @Syati in https://github.com/Syati/structured_params/pull/6
|
21
|
+
* Improve error handling and serialization features by @Syati in https://github.com/Syati/structured_params/pull/1
|
29
22
|
|
23
|
+
**Full Changelog**: https://github.com/Syati/structured_params/compare/v0.1.0...v0.2.0
|
30
24
|
|
31
|
-
|
32
|
-
|
33
|
-
All notable changes to this project will be documented in this file.
|
34
|
-
|
35
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
36
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
37
|
-
|
38
|
-
## [0.2.0] - 2025-09-05
|
39
|
-
|
40
|
-
## What's Changed
|
41
|
-
* Improve error handling and serialization features by @Syati in https://github.com/Syati/structured_params/pull/1
|
25
|
+
## [0.1.0] - Initial Release
|
42
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
|
43
34
|
|
44
|
-
**Full Changelog**: https://github.com/Syati/structured_params/compare/v0.1.4...v0.2.0
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
**Full Changelog**: https://github.com/Syati/structured_params/compare/v0.1.3...v0.1.4
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
### Fixed
|
53
|
-
- Fixed error key consistency issue where `errors.import` was using string keys instead of symbol keys
|
54
|
-
- Updated method names and comments to use consistent 'structured' terminology instead of 'nested'
|
55
|
-
- Fixed type annotations for method calls requiring explicit parameters
|
56
|
-
|
57
|
-
### Changed
|
58
|
-
- Renamed methods for better consistency:
|
59
|
-
- `each_nested_attribute_name` → `each_structured_attribute_name`
|
60
|
-
- `validate_nested_parameters` → `validate_structured_parameters`
|
61
|
-
- `import_nested_errors` → `import_structured_errors`
|
62
|
-
- `serialize_nested_value` → `serialize_structured_value`
|
63
|
-
- Updated documentation to reflect current `:object` and `:array` types instead of `:nested`
|
64
|
-
|
65
|
-
## [0.1.0] - Initial Release
|
66
|
-
|
67
|
-
### Added
|
68
|
-
- Initial implementation of StructuredParams with support for structured objects and arrays
|
69
|
-
- ActiveModel integration for validation and attributes
|
70
|
-
- Strong Parameters compatibility
|
71
|
-
- Type system with Object and Array types
|
72
|
-
- RBS type definitions
|
73
|
-
- Comprehensive test suite
|
@@ -73,17 +73,26 @@ module StructuredParams
|
|
73
73
|
end
|
74
74
|
|
75
75
|
# Convert structured objects to Hash and get attributes
|
76
|
-
#: (symbolize:
|
77
|
-
#: (symbolize:
|
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
|
@@ -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:
|
42
|
-
# : (symbolize:
|
43
|
-
def attributes: (symbolize:
|
44
|
-
| (symbolize:
|
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
|