active_dry_form 1.4.3 → 1.5.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/Gemfile.lock +54 -46
- data/README.md +41 -1
- data/active_dry_form.gemspec +48 -0
- data/lib/active_dry_form/builder.rb +1 -1
- data/lib/active_dry_form/form.rb +7 -2
- data/lib/active_dry_form/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f2b46a8269802eeb6b10b264a398d92d51897a1b5ddac8f3f52a06b6ca3b47b6
|
|
4
|
+
data.tar.gz: 0526caf682091f26d7d9883ea2aa659c326a993a4198ba26df8c97a73193a295
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 252957c5e2724661dd02ed64c546dd745a5133b08ecc0087ea3beda3f37339eb4f9ccf537ca8810f685fd1c7fe0181aadf5d3a95a4cfa47acf2c3b2c3ec44acc
|
|
7
|
+
data.tar.gz: daf080ded69f3a74717dc3918c9f9585292e096fcbd858b47782b14472440257df8dc05eaf9d749fac93bf9c172015ceefdbd6c7297c48e7f71eef474d877e8e
|
data/Gemfile.lock
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
GIT
|
|
2
2
|
remote: https://github.com/corp-gp/rubocop-gp.git
|
|
3
|
-
revision:
|
|
3
|
+
revision: e3d33016bb3b9945ce9d8d22e77825a223de1a5c
|
|
4
4
|
specs:
|
|
5
5
|
rubocop-gp (0.0.4)
|
|
6
6
|
rubocop
|
|
@@ -27,7 +27,7 @@ GIT
|
|
|
27
27
|
PATH
|
|
28
28
|
remote: .
|
|
29
29
|
specs:
|
|
30
|
-
active_dry_form (1.
|
|
30
|
+
active_dry_form (1.5.0)
|
|
31
31
|
actionpack
|
|
32
32
|
activerecord
|
|
33
33
|
dry-configurable
|
|
@@ -69,15 +69,15 @@ GEM
|
|
|
69
69
|
minitest (>= 5.1)
|
|
70
70
|
mutex_m
|
|
71
71
|
tzinfo (~> 2.0)
|
|
72
|
-
ast (2.4.
|
|
73
|
-
base64 (0.
|
|
74
|
-
bigdecimal (3.1
|
|
72
|
+
ast (2.4.3)
|
|
73
|
+
base64 (0.3.0)
|
|
74
|
+
bigdecimal (3.3.1)
|
|
75
75
|
builder (3.3.0)
|
|
76
|
-
concurrent-ruby (1.3.
|
|
77
|
-
connection_pool (2.
|
|
76
|
+
concurrent-ruby (1.3.6)
|
|
77
|
+
connection_pool (2.5.5)
|
|
78
78
|
crass (1.0.6)
|
|
79
79
|
diff-lcs (1.5.1)
|
|
80
|
-
drb (2.2.
|
|
80
|
+
drb (2.2.3)
|
|
81
81
|
dry-configurable (1.2.0)
|
|
82
82
|
dry-core (~> 1.0, < 2)
|
|
83
83
|
zeitwerk (~> 2.6)
|
|
@@ -108,25 +108,27 @@ GEM
|
|
|
108
108
|
dry-schema (>= 1.12, < 2)
|
|
109
109
|
zeitwerk (~> 2.6)
|
|
110
110
|
erubi (1.13.0)
|
|
111
|
-
i18n (1.14.
|
|
111
|
+
i18n (1.14.8)
|
|
112
112
|
concurrent-ruby (~> 1.0)
|
|
113
|
-
json (2.7
|
|
114
|
-
language_server-protocol (3.17.0.
|
|
113
|
+
json (2.19.7)
|
|
114
|
+
language_server-protocol (3.17.0.5)
|
|
115
|
+
lint_roller (1.1.0)
|
|
115
116
|
loofah (2.22.0)
|
|
116
117
|
crass (~> 1.0.2)
|
|
117
118
|
nokogiri (>= 1.12.0)
|
|
118
|
-
minitest (5.
|
|
119
|
-
mutex_m (0.
|
|
119
|
+
minitest (5.27.0)
|
|
120
|
+
mutex_m (0.3.0)
|
|
120
121
|
nokogiri (1.16.6-arm64-darwin)
|
|
121
122
|
racc (~> 1.4)
|
|
122
123
|
nokogiri (1.16.6-x86_64-linux)
|
|
123
124
|
racc (~> 1.4)
|
|
124
|
-
parallel (1.
|
|
125
|
-
parser (3.3.
|
|
125
|
+
parallel (1.28.0)
|
|
126
|
+
parser (3.3.11.1)
|
|
126
127
|
ast (~> 2.4.1)
|
|
127
128
|
racc
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
prism (1.9.0)
|
|
130
|
+
racc (1.8.1)
|
|
131
|
+
rack (3.2.6)
|
|
130
132
|
rack-session (2.0.0)
|
|
131
133
|
rack (>= 3.0.0)
|
|
132
134
|
rack-test (2.1.0)
|
|
@@ -140,9 +142,7 @@ GEM
|
|
|
140
142
|
nokogiri (~> 1.14)
|
|
141
143
|
rainbow (3.1.1)
|
|
142
144
|
rake (13.2.1)
|
|
143
|
-
regexp_parser (2.
|
|
144
|
-
rexml (3.3.1)
|
|
145
|
-
strscan
|
|
145
|
+
regexp_parser (2.12.0)
|
|
146
146
|
rspec (3.13.0)
|
|
147
147
|
rspec-core (~> 3.13.0)
|
|
148
148
|
rspec-expectations (~> 3.13.0)
|
|
@@ -156,44 +156,52 @@ GEM
|
|
|
156
156
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
157
157
|
rspec-support (~> 3.13.0)
|
|
158
158
|
rspec-support (3.13.1)
|
|
159
|
-
rubocop (1.
|
|
159
|
+
rubocop (1.86.2)
|
|
160
160
|
json (~> 2.3)
|
|
161
|
-
language_server-protocol (
|
|
162
|
-
|
|
161
|
+
language_server-protocol (~> 3.17.0.2)
|
|
162
|
+
lint_roller (~> 1.1.0)
|
|
163
|
+
parallel (>= 1.10)
|
|
163
164
|
parser (>= 3.3.0.2)
|
|
164
165
|
rainbow (>= 2.2.2, < 4.0)
|
|
165
|
-
regexp_parser (>=
|
|
166
|
-
|
|
167
|
-
rubocop-ast (>= 1.31.1, < 2.0)
|
|
166
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
167
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
168
168
|
ruby-progressbar (~> 1.7)
|
|
169
|
-
unicode-display_width (>= 2.4.0, <
|
|
170
|
-
rubocop-ast (1.
|
|
171
|
-
parser (>= 3.3.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
rubocop (~> 1.
|
|
176
|
-
rubocop-
|
|
177
|
-
|
|
178
|
-
rubocop
|
|
179
|
-
rubocop-
|
|
169
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
170
|
+
rubocop-ast (1.49.1)
|
|
171
|
+
parser (>= 3.3.7.2)
|
|
172
|
+
prism (~> 1.7)
|
|
173
|
+
rubocop-capybara (2.23.0)
|
|
174
|
+
lint_roller (~> 1.1)
|
|
175
|
+
rubocop (~> 1.81)
|
|
176
|
+
rubocop-factory_bot (2.28.0)
|
|
177
|
+
lint_roller (~> 1.1)
|
|
178
|
+
rubocop (~> 1.72, >= 1.72.1)
|
|
179
|
+
rubocop-performance (1.26.1)
|
|
180
|
+
lint_roller (~> 1.1)
|
|
181
|
+
rubocop (>= 1.75.0, < 2.0)
|
|
182
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
183
|
+
rubocop-rails (2.35.3)
|
|
180
184
|
activesupport (>= 4.2.0)
|
|
185
|
+
lint_roller (~> 1.1)
|
|
181
186
|
rack (>= 1.1)
|
|
182
|
-
rubocop (>= 1.
|
|
183
|
-
rubocop-ast (>= 1.
|
|
184
|
-
rubocop-rspec (3.0
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
rubocop (>= 1.75.0, < 2.0)
|
|
188
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
|
189
|
+
rubocop-rspec (3.9.0)
|
|
190
|
+
lint_roller (~> 1.1)
|
|
191
|
+
rubocop (~> 1.81)
|
|
192
|
+
rubocop-rspec_rails (2.32.0)
|
|
193
|
+
lint_roller (~> 1.1)
|
|
194
|
+
rubocop (~> 1.72, >= 1.72.1)
|
|
195
|
+
rubocop-rspec (~> 3.5)
|
|
189
196
|
ruby-progressbar (1.13.0)
|
|
190
197
|
sqlite3 (1.7.3-arm64-darwin)
|
|
191
198
|
sqlite3 (1.7.3-x86_64-linux)
|
|
192
|
-
strscan (3.1.0)
|
|
193
199
|
timeout (0.4.1)
|
|
194
200
|
tzinfo (2.0.6)
|
|
195
201
|
concurrent-ruby (~> 1.0)
|
|
196
|
-
unicode-display_width (2.
|
|
202
|
+
unicode-display_width (3.2.0)
|
|
203
|
+
unicode-emoji (~> 4.1)
|
|
204
|
+
unicode-emoji (4.2.0)
|
|
197
205
|
zeitwerk (2.6.16)
|
|
198
206
|
|
|
199
207
|
PLATFORMS
|
data/README.md
CHANGED
|
@@ -44,7 +44,7 @@ form.update # Failure(:invalid_form)
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
Methods `form.update` and `form.create` return [Result monad](https://dry-rb.org/gems/dry-monads/1.3/result/)
|
|
47
|
+
Methods `form.update` and `form.create` return [Result monad](https://dry-rb.org/gems/dry-monads/1.3/result/). Actions must explicitly return `Success` or `Failure`; any other return value raises `ActiveDryForm::Form::ResultError`.
|
|
48
48
|
|
|
49
49
|
```ruby
|
|
50
50
|
# app/forms/product_form.rb
|
|
@@ -73,6 +73,46 @@ class ProductForm < Form
|
|
|
73
73
|
end
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
+
Actions also handle `Dry::Monads::UnwrapError` raised by `value!` (including service methods such as `call!`). The action returns the original `Failure` and sets `form.base_errors` to `Array.wrap(result.failure).map(&:to_s)`. Other exceptions propagate normally.
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
class CaptchaValidateService
|
|
80
|
+
extend Dry::Monads[:result]
|
|
81
|
+
|
|
82
|
+
def self.call(token:, ip:, hostname:)
|
|
83
|
+
return Failure('Captcha token is missing') if token.blank?
|
|
84
|
+
|
|
85
|
+
verified = CaptchaClient.verify(token:, ip:, hostname:)
|
|
86
|
+
return Failure('Invalid captcha') unless verified
|
|
87
|
+
|
|
88
|
+
Success()
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def self.call!(**params)
|
|
92
|
+
# value! unwraps Success and returns its value.
|
|
93
|
+
# For Failure, it raises Dry::Monads::UnwrapError with the original monad in receiver.
|
|
94
|
+
call(**params).value!
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
class UserForm < Form
|
|
99
|
+
fields :user do
|
|
100
|
+
params do
|
|
101
|
+
required(:email).filled(:string)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
action def create(token:, ip:, hostname:)
|
|
106
|
+
# If verification returns Failure('Invalid captcha'), call! raises Dry::Monads::UnwrapError.
|
|
107
|
+
# The action wrapper catches it, returns the original Failure, and sets
|
|
108
|
+
# form.base_errors to ['Invalid captcha'], skipping user creation.
|
|
109
|
+
# Other exceptions, including those from CaptchaClient.verify, propagate to the caller.
|
|
110
|
+
CaptchaValidateService.call!(token:, ip:, hostname:)
|
|
111
|
+
Success(User.create!(data))
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
```
|
|
115
|
+
|
|
76
116
|
In your controller
|
|
77
117
|
|
|
78
118
|
```ruby
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/active_dry_form/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'active_dry_form'
|
|
7
|
+
spec.version = ActiveDryForm::VERSION
|
|
8
|
+
spec.authors = ['Ermolaev Andrey']
|
|
9
|
+
spec.email = ['andruhafirst@yandex.ru']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'Form validation for Rails with Dry-Validation'
|
|
12
|
+
spec.description = 'Form validation for Rails with Dry-Validation'
|
|
13
|
+
spec.homepage = 'https://github.com/corp-gp/active_dry_form'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = '>= 3.1.0'
|
|
16
|
+
|
|
17
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
|
18
|
+
|
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
20
|
+
spec.metadata['source_code_uri'] = 'https://github.com/corp-gp/active_dry_form'
|
|
21
|
+
|
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
24
|
+
spec.files =
|
|
25
|
+
Dir.chdir(File.expand_path(__dir__)) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
spec.bindir = 'exe'
|
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
32
|
+
spec.require_paths = ['lib']
|
|
33
|
+
|
|
34
|
+
# Uncomment to register a new dependency of your gem
|
|
35
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
|
36
|
+
|
|
37
|
+
# For more information and examples about making a new gem, checkout our
|
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
39
|
+
#
|
|
40
|
+
#
|
|
41
|
+
spec.add_dependency 'actionpack'
|
|
42
|
+
spec.add_dependency 'activerecord'
|
|
43
|
+
spec.add_dependency 'dry-configurable'
|
|
44
|
+
spec.add_dependency 'dry-monads'
|
|
45
|
+
spec.add_dependency 'dry-validation'
|
|
46
|
+
|
|
47
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
48
|
+
end
|
|
@@ -57,7 +57,7 @@ module ActiveDryForm
|
|
|
57
57
|
@template.content_tag(:div, class: ActiveDryForm.config.css_classes.base_error) do
|
|
58
58
|
@template.content_tag(:ul) do
|
|
59
59
|
# внутри ошибки может быть html
|
|
60
|
-
@object.base_errors.map { @template.content_tag(:li, _1.html_safe) }.join.html_safe
|
|
60
|
+
@object.base_errors.map { @template.content_tag(:li, _1.to_s.html_safe) }.join.html_safe
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
end
|
data/lib/active_dry_form/form.rb
CHANGED
|
@@ -27,11 +27,16 @@ module ActiveDryForm
|
|
|
27
27
|
validate
|
|
28
28
|
return Failure(:invalid_form) unless valid?
|
|
29
29
|
|
|
30
|
-
result =
|
|
30
|
+
result =
|
|
31
|
+
begin
|
|
32
|
+
__#{method}(...)
|
|
33
|
+
rescue ::Dry::Monads::UnwrapError => e
|
|
34
|
+
e.receiver
|
|
35
|
+
end
|
|
31
36
|
|
|
32
37
|
case result
|
|
33
38
|
when ::Dry::Monads::Result::Failure
|
|
34
|
-
@base_errors = Array.wrap(result.failure)
|
|
39
|
+
@base_errors = Array.wrap(result.failure).map(&:to_s)
|
|
35
40
|
when ::Dry::Monads::Result::Success
|
|
36
41
|
else
|
|
37
42
|
raise ResultError, 'method `#{method}` must return `monad`'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_dry_form
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ermolaev Andrey
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionpack
|
|
@@ -96,6 +96,7 @@ files:
|
|
|
96
96
|
- LICENSE.txt
|
|
97
97
|
- README.md
|
|
98
98
|
- Rakefile
|
|
99
|
+
- active_dry_form.gemspec
|
|
99
100
|
- bin/console
|
|
100
101
|
- bin/setup
|
|
101
102
|
- config/locales/dry_validation.ru.yml
|