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 +4 -4
- data/CHANGELOG.md +32 -33
- 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 +21 -9
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,35 +1,34 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
-
|
31
|
-
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
|
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:
|
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
|
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.
|
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:
|
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:
|
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:
|
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:
|
51
|
+
version: '9.0'
|
40
52
|
description: ''
|
41
53
|
email:
|
42
54
|
- mizuki-y@syati.info
|