solid-process 0.5.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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +2 -2
- data/docs/040_ADVANCED_USAGE.md +74 -0
- data/lib/solid/model.rb +5 -0
- data/lib/solid/process/version.rb +1 -1
- data/lib/solid/value.rb +4 -0
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8806338db8f3194c5cd5a99ba56a2429f627426f51ac5cfece57d4a629e5328e
|
|
4
|
+
data.tar.gz: ae0f3c7a19a02b1780e5cd6551d6ae6f0011ad657a3f88778a05fc61400e0d2e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4981f758d2c29c7449d1852303da4cfded01037ca136729b9ba18887ccf7f172ef833b591b3ee9c42ad61dd920dfa7302df1d99792b84b46681c516631fe1294
|
|
7
|
+
data.tar.gz: dfa3f9eb10870116af8caee157411f983750d4c1898777fc78b42389f7219bda094aa4a48ae759ad1b5ab33dbc3b356025b72dcdbbb4fb60aa7c9bff1637ab8f
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.6.0] - 2026-01-28
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Add conditional `normalizes` support to `Solid::Model` (requires Rails 8.1+ with `ActiveModel::Attributes::Normalization`).
|
|
8
|
+
|
|
9
|
+
- Add `normalizes` to `Solid::Value`, automatically prepending `:value` as the attribute name.
|
|
10
|
+
|
|
3
11
|
## [0.5.0] - 2025-01-27
|
|
4
12
|
|
|
5
13
|
### Added
|
data/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
<h1 align="center" id="-solidprocess">⚛️ Solid::Process</h1>
|
|
3
3
|
<p align="center"><i>Write business logic for Ruby/Rails that scales.</i></p>
|
|
4
4
|
<p align="center">
|
|
5
|
-
<a href="https://
|
|
6
|
-
<a href="https://
|
|
5
|
+
<a href="https://qlty.sh/gh/solid-process/projects/solid-process"><img src="https://qlty.sh/gh/solid-process/projects/solid-process/maintainability.svg" alt="Maintainability" /></a>
|
|
6
|
+
<a href="https://qlty.sh/gh/solid-process/projects/solid-process"><img src="https://qlty.sh/gh/solid-process/projects/solid-process/coverage.svg" alt="Code Coverage" /></a>
|
|
7
7
|
<img src="https://img.shields.io/badge/Ruby%20%3E%3D%202.7%2C%20%3C%3D%20Head-ruby.svg?colorA=444&colorB=333" alt="Ruby">
|
|
8
8
|
<img src="https://img.shields.io/badge/Rails%20%3E%3D%206.0%2C%20%3C%3D%20Edge-rails.svg?colorA=444&colorB=333" alt="Rails">
|
|
9
9
|
</p>
|
data/docs/040_ADVANCED_USAGE.md
CHANGED
|
@@ -94,3 +94,77 @@ class User::Registration < Solid::Process
|
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
96
|
```
|
|
97
|
+
|
|
98
|
+
## Input Normalization
|
|
99
|
+
|
|
100
|
+
### Using `before_validation` (all Rails versions)
|
|
101
|
+
|
|
102
|
+
The example above uses `before_validation` to normalize the email attribute. This approach works on all supported Rails versions, but normalization only runs when `valid?` is called:
|
|
103
|
+
|
|
104
|
+
```ruby
|
|
105
|
+
input do
|
|
106
|
+
attribute :email, :string
|
|
107
|
+
|
|
108
|
+
before_validation do
|
|
109
|
+
self.email = email.downcase.strip
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Using `normalizes` (Rails 8.1+)
|
|
115
|
+
|
|
116
|
+
Rails 8.1 introduced `ActiveModel::Attributes::Normalization`, which provides a declarative way to normalize attributes. When available, `Solid::Model` automatically includes it.
|
|
117
|
+
|
|
118
|
+
Unlike `before_validation`, `normalizes` applies on attribute assignment, so the value is normalized immediately:
|
|
119
|
+
|
|
120
|
+
```ruby
|
|
121
|
+
input do
|
|
122
|
+
attribute :email, :string
|
|
123
|
+
|
|
124
|
+
normalizes :email, with: -> { _1.strip.downcase }
|
|
125
|
+
end
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### Normalize multiple attributes with the same rule
|
|
129
|
+
|
|
130
|
+
```ruby
|
|
131
|
+
input do
|
|
132
|
+
attribute :email, :string
|
|
133
|
+
attribute :username, :string
|
|
134
|
+
|
|
135
|
+
normalizes :email, :username, with: -> { _1.strip.downcase }
|
|
136
|
+
end
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
#### Different normalizations per attribute
|
|
140
|
+
|
|
141
|
+
```ruby
|
|
142
|
+
input do
|
|
143
|
+
attribute :email, :string
|
|
144
|
+
attribute :phone, :string
|
|
145
|
+
|
|
146
|
+
normalizes :email, with: -> { _1.strip.downcase }
|
|
147
|
+
normalizes :phone, with: -> { _1.delete("^0-9").delete_prefix("1") }
|
|
148
|
+
end
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
#### Apply normalization to `nil` values
|
|
152
|
+
|
|
153
|
+
By default, `normalizes` skips `nil` values. Use `apply_to_nil: true` to change this:
|
|
154
|
+
|
|
155
|
+
```ruby
|
|
156
|
+
input do
|
|
157
|
+
attribute :phone, :string
|
|
158
|
+
|
|
159
|
+
normalizes :phone, with: -> { _1&.delete("^0-9") || "" }, apply_to_nil: true
|
|
160
|
+
end
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
#### Normalize a value without instantiation
|
|
164
|
+
|
|
165
|
+
Use `normalize_value_for` on the input class to normalize a value directly:
|
|
166
|
+
|
|
167
|
+
```ruby
|
|
168
|
+
UserRegistration.input.normalize_value_for(:email, " FOO@BAR.COM\n")
|
|
169
|
+
# => "foo@bar.com"
|
|
170
|
+
```
|
data/lib/solid/model.rb
CHANGED
|
@@ -20,6 +20,11 @@ module Solid::Model
|
|
|
20
20
|
include ::ActiveModel.const_defined?(:Access, false) ? ::ActiveModel::Access : ::Solid::Model::Access
|
|
21
21
|
|
|
22
22
|
include ::ActiveModel::Attributes
|
|
23
|
+
|
|
24
|
+
if ::ActiveModel::Attributes.const_defined?(:Normalization, false)
|
|
25
|
+
include ::ActiveModel::Attributes::Normalization
|
|
26
|
+
end
|
|
27
|
+
|
|
23
28
|
include ::ActiveModel::Dirty
|
|
24
29
|
include ::ActiveModel::Validations::Callbacks
|
|
25
30
|
|
data/lib/solid/value.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: solid-process
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rodrigo Serradura
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: solid-result
|
|
@@ -123,7 +122,6 @@ metadata:
|
|
|
123
122
|
source_code_uri: https://github.com/serradura/solid-process
|
|
124
123
|
changelog_uri: https://github.com/solid-process/solid-process/blob/main/CHANGELOG.md
|
|
125
124
|
rubygems_mfa_required: 'true'
|
|
126
|
-
post_install_message:
|
|
127
125
|
rdoc_options: []
|
|
128
126
|
require_paths:
|
|
129
127
|
- lib
|
|
@@ -138,8 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
138
136
|
- !ruby/object:Gem::Version
|
|
139
137
|
version: '0'
|
|
140
138
|
requirements: []
|
|
141
|
-
rubygems_version: 3.2
|
|
142
|
-
signing_key:
|
|
139
|
+
rubygems_version: 3.7.2
|
|
143
140
|
specification_version: 4
|
|
144
141
|
summary: Write business logic for Ruby/Rails that scales.
|
|
145
142
|
test_files: []
|