structured_params 0.1.0 → 0.1.1

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: 9c06ea969ca1b6ba0b64271bc9b168519fecbb48d754c234489e9b509cd22578
4
- data.tar.gz: 9f10004fd987e2e5af527857860d72d6d4ccaf19ec98dec0ac673c9db20ec473
3
+ metadata.gz: 465e05cd489fded0858ba6430045d1ed8a479b864f7190e0e561e095b979224a
4
+ data.tar.gz: d79203675ccaff61fb740f30af56056bc77a2356b703080a58468eaa852ed614
5
5
  SHA512:
6
- metadata.gz: 6354a4d7f609f46093ed55f8cab4873d2f0f15370f0ad4a1e6719e7e5e02ff12a17ce0bd34f5b82bb1129ed6d933cfa51aa6de353b7fe7cf18882d857f3daa23
7
- data.tar.gz: ff1fe2be0beb5024f7afa1e8f41a4b32dc55aeee061d633d40ca0052802129b507962d0a38bcad826d10da98ac7c64bd3b25edb7f6bc4c65a3117449fbc8aef9
6
+ metadata.gz: ab616001f00cbddd9e88603869019d00c4f185f80d5c4476b1af0c670c46d96b00e0cf6bf668e1f39c20c1d8e7537d18b29fab23f00beb697096cdff5873226d
7
+ data.tar.gz: bd10044d6178f1ce7e6b8ac60c9b437c6efb329d5ad0077dd167feae0ff34253457f9f492b2096f2138e159fb3d6fbbbc8f86f0326c5f72999ede42b5525ad0e
data/CHANGELOG.md ADDED
@@ -0,0 +1,31 @@
1
+ # Changelog
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.1] - 2025-01-03
9
+
10
+ ### Fixed
11
+ - Fixed error key consistency issue where `errors.import` was using string keys instead of symbol keys
12
+ - Updated method names and comments to use consistent 'structured' terminology instead of 'nested'
13
+ - Fixed type annotations for method calls requiring explicit parameters
14
+
15
+ ### Changed
16
+ - Renamed methods for better consistency:
17
+ - `each_nested_attribute_name` → `each_structured_attribute_name`
18
+ - `validate_nested_parameters` → `validate_structured_parameters`
19
+ - `import_nested_errors` → `import_structured_errors`
20
+ - `serialize_nested_value` → `serialize_structured_value`
21
+ - Updated documentation to reflect current `:object` and `:array` types instead of `:nested`
22
+
23
+ ## [0.1.0] - Initial Release
24
+
25
+ ### Added
26
+ - Initial implementation of StructuredParams with support for structured objects and arrays
27
+ - ActiveModel integration for validation and attributes
28
+ - Strong Parameters compatibility
29
+ - Type system with Object and Array types
30
+ - RBS type definitions
31
+ - Comprehensive test suite
@@ -2,12 +2,12 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module StructuredParams
5
- # Parameter model that supports nested structures
5
+ # Parameter model that supports structured objects and arrays
6
6
  #
7
7
  # Usage example:
8
8
  # class UserParameter < StructuredParams::Params
9
9
  # attribute :name, :string
10
- # attribute :address, :nested, value_class: AddressParameter
10
+ # attribute :address, :object, value_class: AddressParameter
11
11
  # attribute :hobbies, :array, value_class: HobbyParameter
12
12
  # attribute :tags, :array, value_type: :string
13
13
  # end
@@ -30,9 +30,9 @@ module StructuredParams
30
30
  end
31
31
  end
32
32
 
33
- # Get names of nested StructuredParams attributes
33
+ # Get names of StructuredParams attributes (object and array types)
34
34
  #: () { (String) -> void } -> void
35
- def each_nested_attribute_name
35
+ def each_structured_attribute_name
36
36
  attribute_types.each do |name, type|
37
37
  yield name if structured_params_type?(type)
38
38
  end
@@ -40,7 +40,7 @@ module StructuredParams
40
40
 
41
41
  private
42
42
 
43
- # Determine if the specified type is a nested parameter type
43
+ # Determine if the specified type is a StructuredParams type
44
44
  #: (untyped) -> bool
45
45
  def structured_params_type?(type)
46
46
  type.is_a?(StructuredParams::Type::Object) ||
@@ -48,8 +48,8 @@ module StructuredParams
48
48
  end
49
49
  end
50
50
 
51
- # Integrate validation of nested objects
52
- validate :validate_nested_parameters
51
+ # Integrate validation of structured objects
52
+ validate :validate_structured_parameters
53
53
 
54
54
  #: (untyped) -> void
55
55
  def initialize(params)
@@ -57,14 +57,14 @@ module StructuredParams
57
57
  super(**processed_params)
58
58
  end
59
59
 
60
- # Convert nested objects to Hash and get attributes
60
+ # Convert structured objects to Hash and get attributes
61
61
  #: (symbolize: bool) -> Hash[untyped, untyped]
62
62
  def attributes(symbolize: false)
63
63
  attrs = super()
64
64
 
65
- self.class.each_nested_attribute_name do |name|
65
+ self.class.each_structured_attribute_name do |name|
66
66
  value = attrs[name.to_s]
67
- attrs[name.to_s] = serialize_nested_value(value)
67
+ attrs[name.to_s] = serialize_structured_value(value)
68
68
  end
69
69
 
70
70
  symbolize ? attrs.deep_symbolize_keys : attrs
@@ -86,40 +86,40 @@ module StructuredParams
86
86
  end
87
87
  end
88
88
 
89
- # Execute nested parameter validation
89
+ # Execute structured parameter validation
90
90
  #: () -> void
91
- def validate_nested_parameters
92
- self.class.each_nested_attribute_name do |attr_name|
91
+ def validate_structured_parameters
92
+ self.class.each_structured_attribute_name do |attr_name|
93
93
  value = attribute(attr_name)
94
94
  next if value.blank?
95
95
 
96
96
  case value
97
97
  when Array
98
- validate_nested_array(attr_name, value)
98
+ validate_structured_array(attr_name, value)
99
99
  else
100
- validate_nested_object(attr_name, value)
100
+ validate_structured_object(attr_name, value)
101
101
  end
102
102
  end
103
103
  end
104
104
 
105
- # Validate nested arrays
105
+ # Validate structured arrays
106
106
  #: (String, Array[untyped]) -> void
107
- def validate_nested_array(attr_name, array_value)
107
+ def validate_structured_array(attr_name, array_value)
108
108
  array_value.each_with_index do |item, index|
109
109
  next if item.valid?(validation_context)
110
110
 
111
111
  error_path = format_error_path(attr_name, index)
112
- import_nested_errors(item.errors, error_path)
112
+ import_structured_errors(item.errors, error_path)
113
113
  end
114
114
  end
115
115
 
116
- # Validate nested objects
116
+ # Validate structured objects
117
117
  #: (String, StructuredParams::Params) -> void
118
- def validate_nested_object(attr_name, object_value)
118
+ def validate_structured_object(attr_name, object_value)
119
119
  return if object_value.valid?(validation_context)
120
120
 
121
- error_path = format_error_path(attr_name)
122
- import_nested_errors(object_value.errors, error_path)
121
+ error_path = format_error_path(attr_name, nil)
122
+ import_structured_errors(object_value.errors, error_path)
123
123
  end
124
124
 
125
125
  # Format error path using dot notation (always consistent)
@@ -130,22 +130,22 @@ module StructuredParams
130
130
  path_parts.join('.')
131
131
  end
132
132
 
133
- # Integrate nested errors into parent errors
133
+ # Integrate structured parameter errors into parent errors
134
134
  #: (untyped, String) -> void
135
- def import_nested_errors(nested_errors, prefix)
136
- nested_errors.each do |error|
137
- errors.import(error, attribute: "#{prefix}.#{error.attribute}")
135
+ def import_structured_errors(structured_errors, prefix)
136
+ structured_errors.each do |error|
137
+ errors.import(error, attribute: :"#{prefix}.#{error.attribute}")
138
138
  end
139
139
  end
140
140
 
141
- # Serialize nested values
141
+ # Serialize structured values
142
142
  #: (untyped) -> untyped
143
- def serialize_nested_value(value)
143
+ def serialize_structured_value(value)
144
144
  case value
145
145
  when Array
146
- value.map(&:attributes)
146
+ value.map { |item| item.attributes(symbolize: false) }
147
147
  when StructuredParams::Params
148
- value.attributes
148
+ value.attributes(symbolize: false)
149
149
  else
150
150
  value
151
151
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module StructuredParams
5
- VERSION = '0.1.0' #: string
5
+ VERSION = '0.1.1' #: string
6
6
  end
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mizuki Yamamoto
@@ -44,6 +44,7 @@ executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
+ - CHANGELOG.md
47
48
  - LICENSE.txt
48
49
  - lib/structured_params.rb
49
50
  - lib/structured_params/params.rb