structured_params 0.3.0 → 0.6.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: f6e173ab053f1e2c0663487baef3cf54059b6f9a49a6e9a5f83583036d3761e9
4
- data.tar.gz: 2cde9e164e2a44671af8f087cfd0dc1f7b5306ee2a21f3b252425d40260c1ff7
3
+ metadata.gz: 66f5daa7a71dd1470ca9f5d8af4d62dd8b0c40227ce6f07812a04206e0083c06
4
+ data.tar.gz: 5c9500ee402ecd0c06ab82503ac13b4ed4800cd2a18b87f4b5fecbba692ad4ac
5
5
  SHA512:
6
- metadata.gz: d84113eb2dbd70e8fbbcb0bae0109dfae9f4d4e3c7314370ac30a22456aa6ae29bfeadbfc73628190a72ce47a699219ec3a71d5531b9e282e6db3c5687fa0000
7
- data.tar.gz: cd094fa7736d631982474a7eaa03b41df44122c532434c0a4fc75b0ef406e4e06997c70d2aaf2cd9ffd106626fcc4e3e63a8fbf9b91d4de98cafc281df895d00
6
+ metadata.gz: 306948118def08f98c24f460f1e5763e72281a2c31e141ba7db9c376ceea5e1a6ac4ab016a28779f84dfa60ebcf74904b62f66d191507c4066c0f9db055067d6
7
+ data.tar.gz: 57d137f7e64e810356f909045a7e250abe82317b8b5574b8b1f2c4db2e2e23476ef48fc792a7cf168cdad646b649261e2bc9548365827645d1b3f5ec327fe8ed
data/CHANGELOG.md CHANGED
@@ -1,73 +1,43 @@
1
1
  # Changelog
2
2
 
3
- ## [0.3.0] - 2025-09-06
3
+ ## [0.6.0] - 2026-02-28
4
4
 
5
5
  ## What's Changed
6
- * Expand Rails compatibility to support Rails 7.2+ through 8.x
6
+ * Update Ruby and Rails versions with RBS and RuboCop adjustments by @Syati in https://github.com/Syati/structured_params/pull/11
7
7
 
8
8
 
9
- **Full Changelog**: https://github.com/Syati/structured_params/compare/v0.2.0...v0.3.0
10
-
11
- ## [0.2.1] - 2025-09-06
9
+ **Full Changelog**: https://github.com/Syati/structured_params/compare/v0.5.0...v0.6.0
12
10
 
11
+ ## [0.5.0] - 2025-09-09
12
+
13
13
  ## What's Changed
14
- * Bump version to 0.2.0 by @Syati in https://github.com/Syati/structured_params/pull/2
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
+ * Update attributes method signatures to use optional keyword arguments… by @Syati in https://github.com/Syati/structured_params/pull/8
19
15
 
20
16
 
21
- **Full Changelog**: https://github.com/Syati/structured_params/compare/v0.2.0...v0.2.1
17
+ **Full Changelog**: https://github.com/Syati/structured_params/compare/v0.3.0...v0.5.0
18
+
19
+ ## [0.3.0] - 2025-09-06
22
20
 
23
21
  ## What's Changed
24
- * Bump version to 0.2.0 by @Syati in https://github.com/Syati/structured_params/pull/2
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
22
+ * Expand Rails compatibility to support Rails 7.2+ through 8.x
29
23
 
24
+ **Full Changelog**: https://github.com/Syati/structured_params/compare/v0.2.0...v0.3.0
25
+
26
+ ## [0.2.0] - 2025-09-05
30
27
 
31
- **Full Changelog**: https://github.com/Syati/structured_params/compare/v0.2.0...v0.2.1
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
28
  ## What's Changed
41
29
  * Improve error handling and serialization features by @Syati in https://github.com/Syati/structured_params/pull/1
42
30
 
31
+ **Full Changelog**: https://github.com/Syati/structured_params/compare/v0.1.0...v0.2.0
32
+
33
+ ## [0.1.0] - Initial Release
34
+
35
+ ### Added
36
+ - Initial implementation of StructuredParams with support for structured objects and arrays
37
+ - ActiveModel integration for validation and attributes
38
+ - Strong Parameters compatibility
39
+ - Type system with Object and Array types
40
+ - RBS type definitions
41
+ - Comprehensive test suite
42
+
43
43
 
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
@@ -18,7 +18,7 @@ module StructuredParams
18
18
  # @rbs @errors: ::StructuredParams::Errors?
19
19
 
20
20
  class << self
21
- # @rbs self.@structured_attributes: Hash[Symbol, singleton(::StructuredParams::Params)]?
21
+ # @rbs @structured_attributes: Hash[Symbol, singleton(::StructuredParams::Params)]?
22
22
 
23
23
  # Generate permitted parameter structure for Strong Parameters
24
24
  #: () -> Array[untyped]
@@ -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
@@ -119,9 +128,7 @@ module StructuredParams
119
128
  end
120
129
 
121
130
  # Validate structured arrays
122
- # @rbs attr_name: Symbol
123
- # @rbs array_value: Array[untyped]
124
- # @rbs return: void
131
+ #: (Symbol, Array[untyped]) -> void
125
132
  def validate_structured_array(attr_name, array_value)
126
133
  array_value.each_with_index do |item, index|
127
134
  next if item.valid?(validation_context)
@@ -132,9 +139,7 @@ module StructuredParams
132
139
  end
133
140
 
134
141
  # Validate structured objects
135
- # @rbs attr_name: Symbol
136
- # @rbs object_value: ::StructuredParams::Params
137
- # @rbs return: void
142
+ #: (Symbol, StructuredParams::Params) -> void
138
143
  def validate_structured_object(attr_name, object_value)
139
144
  return if object_value.valid?(validation_context)
140
145
 
@@ -151,13 +156,22 @@ module StructuredParams
151
156
  end
152
157
 
153
158
  # Serialize structured values
154
- #: (untyped) -> untyped
155
- def serialize_structured_value(value)
159
+ #: (untyped, ?compact_mode: :none | :nil_only | :all_blank) -> untyped
160
+ def serialize_structured_value(value, compact_mode: :none)
156
161
  case value
157
162
  when Array
158
- value.map { |item| item.attributes(symbolize: false) }
163
+ result = value.map { |item| item.attributes(symbolize: false, compact_mode: compact_mode) }
164
+
165
+ case compact_mode
166
+ when :all_blank
167
+ result.compact_blank
168
+ when :nil_only
169
+ result.compact
170
+ else
171
+ result
172
+ end
159
173
  when StructuredParams::Params
160
- value.attributes(symbolize: false)
174
+ value.attributes(symbolize: false, compact_mode: compact_mode)
161
175
  else
162
176
  value
163
177
  end
@@ -10,6 +10,7 @@ module StructuredParams
10
10
  # Get permitted parameter names for use with Strong Parameters
11
11
  # @rbs!
12
12
  # def permit_attribute_names: () -> ::Array[untyped]
13
+
13
14
  delegate :permit_attribute_names, to: :value_class
14
15
 
15
16
  #: (value_class: singleton(StructuredParams::Params), **untyped) -> void
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module StructuredParams
5
- VERSION = '0.3.0' #: string
5
+ VERSION = '0.6.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.3.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mizuki Yamamoto
@@ -86,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 3.0.0
89
+ version: 3.2.0
90
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - ">="