You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/basic-usage.md
+28-10Lines changed: 28 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,15 @@
1
1
# Basic Usage
2
2
3
+
Define a parameter class by inheriting from `StructuredParams::Params`. Declare typed attributes with `attribute` and use standard ActiveModel validations.
4
+
5
+
## Table of Contents
6
+
7
+
-[Basic Parameter Class](#basic-parameter-class)
8
+
-[Nested Objects](#nested-objects)
9
+
-[Arrays](#arrays)
10
+
-[Array of Primitive Types](#array-of-primitive-types)
11
+
-[Array of Nested Objects](#array-of-nested-objects)
12
+
3
13
## Basic Parameter Class
4
14
5
15
```ruby
@@ -25,6 +35,8 @@ end
25
35
26
36
## Nested Objects
27
37
38
+
Use `attribute :name, :object, value_class: SomeParams` to define a nested object.
39
+
28
40
```ruby
29
41
classAddressParams < StructuredParams::Params
30
42
attribute :street, :string
@@ -48,41 +60,47 @@ params = {
48
60
}
49
61
50
62
user_params =UserParams.new(params)
51
-
user_params.address # => AddressParams instance
52
-
user_params.address.city # => "New York"
63
+
user_params.address # => AddressParams instance
64
+
user_params.address.city # => "New York"
53
65
```
54
66
55
67
## Arrays
56
68
69
+
Use `attribute :name, :array, ...` to define an array attribute. Specify `value_type` for scalar elements or `value_class` for object elements.
0 commit comments