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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56d7e7dae11f894dafd8cd1970ccf6fa1a9e6f6879a8f6370a3c5fa3b8419fcd
4
- data.tar.gz: c15ca09276f4e0a366c980fd44cb6885f7cb5e1439786222c324828b2e7a5632
3
+ metadata.gz: 8806338db8f3194c5cd5a99ba56a2429f627426f51ac5cfece57d4a629e5328e
4
+ data.tar.gz: ae0f3c7a19a02b1780e5cd6551d6ae6f0011ad657a3f88778a05fc61400e0d2e
5
5
  SHA512:
6
- metadata.gz: 3a7afa31c7de01092d6c75130d50e557c83e7e8b12b7a30667fce3bbfdb7c2876298907da67c8c0cfa8b1e1bd375b88d11d106d800bb628cb70e7efe7203324d
7
- data.tar.gz: 53b395cec3553f20305db78fc24b51b09283034310363f26bdf53711aec85021aa5aa85cb24645d692d85df0218c8cec2700f42c315f983507dc27375f65f80d
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://codeclimate.com/github/solid-process/solid-process/maintainability"><img src="https://api.codeclimate.com/v1/badges/643a53e99bb591321c9f/maintainability" /></a>
6
- <a href="https://codeclimate.com/github/solid-process/solid-process/test_coverage"><img src="https://api.codeclimate.com/v1/badges/643a53e99bb591321c9f/test_coverage" /></a>
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>
@@ -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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Solid
4
4
  class Process
5
- VERSION = "0.5.0"
5
+ VERSION = "0.6.0"
6
6
  end
7
7
  end
data/lib/solid/value.rb CHANGED
@@ -17,6 +17,10 @@ module Solid::Value
17
17
  def validates(...)
18
18
  super(:value, ...)
19
19
  end
20
+
21
+ def normalizes(...)
22
+ super(:value, ...)
23
+ end
20
24
  end
21
25
 
22
26
  def self.included(subclass)
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.5.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: 2026-01-27 00:00:00.000000000 Z
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.33
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: []