application_form 0.5.0 → 0.5.4
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/README.md +12 -5
- data/application_form.gemspec +2 -2
- data/lib/application_form.rb +6 -5
- data/lib/application_form/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef96372acd66b16420e3a1c63699eaf37f10b92cba2d834c3139bbdc056a8b46
|
4
|
+
data.tar.gz: ed40f7353a74c021381e579361a49c9c88f29f22df9f18a3bfd80d43ab132c76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05220ee71ee33781a8ddeb624aa639e2afddd57035924b1270549218948509a9d9493a79d052dd6f2b320fe33df8d26750be2f6c7e8320ed0a457105ef89c18b
|
7
|
+
data.tar.gz: d805e59a90b554cb232ff55ed33700d402bb116d88140eaacd5319e42491dc15196f2df3ddd47ef11e7a011d092ac415ff69c9f9c9c1032212e781b076c589a8
|
data/README.md
CHANGED
@@ -66,7 +66,14 @@ class UserSignUpForm < User
|
|
66
66
|
end
|
67
67
|
```
|
68
68
|
|
69
|
-
|
69
|
+
```
|
70
|
+
form = UserSignUpForm.new(user_params)
|
71
|
+
form.valid?
|
72
|
+
```
|
73
|
+
|
74
|
+
### Usage with `becomes`
|
75
|
+
|
76
|
+
In some cases it is necessary to use ActiveRecord object directly without form. For such cases conveniently to use method `becomes()` (built-in ActiveRecord):
|
70
77
|
|
71
78
|
```ruby
|
72
79
|
user = User.find(params[:id])
|
@@ -93,19 +100,19 @@ form = ReservationCreateForm.new(prepared_params)
|
|
93
100
|
if form.checks_passed?
|
94
101
|
# ...
|
95
102
|
else
|
96
|
-
render_error!(form.first_failed_check) # form.first_failed_check returns "max_number_of_reservations_reached"
|
103
|
+
render_error!(form.first_failed_check) # form.first_failed_check returns "reservation.error.max_number_of_reservations_reached"
|
97
104
|
end
|
98
105
|
```
|
99
106
|
|
100
|
-
You can also
|
107
|
+
You can also assign check to a specific field:
|
101
108
|
|
102
|
-
```
|
109
|
+
```ruby
|
103
110
|
check :end_at_must_be_greater_then_start_at, ->(form) { form.end_at > form.start_at }, :end_at
|
104
111
|
```
|
105
112
|
|
106
113
|
In this case it will work as a regular validation.
|
107
114
|
|
108
|
-
### `
|
115
|
+
### `assign_attrs`
|
109
116
|
|
110
117
|
It works as regular `assign_attributes` but it also returns the object, so that you can chain it:
|
111
118
|
|
data/application_form.gemspec
CHANGED
@@ -10,12 +10,12 @@ Gem::Specification.new do |spec|
|
|
10
10
|
|
11
11
|
spec.summary = 'Painless forms for ActiveRecord'
|
12
12
|
spec.description = 'Lightweight inheritance based forms solution'
|
13
|
-
spec.homepage = 'https://github.com/
|
13
|
+
spec.homepage = 'https://github.com/rbbr-io/application_form'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
16
16
|
|
17
17
|
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
-
spec.metadata['source_code_uri'] = 'https://github.com/
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/rbbr-io/application_form.git'
|
19
19
|
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
20
|
|
21
21
|
# Specify which files should be added to the gem when it is released.
|
data/lib/application_form.rb
CHANGED
@@ -35,11 +35,12 @@ module ApplicationForm
|
|
35
35
|
@_permitted_args || (superclass.respond_to?(:_permitted_args) && superclass._permitted_args) || []
|
36
36
|
end
|
37
37
|
|
38
|
-
def check(
|
38
|
+
def check(key, block, field = :base)
|
39
39
|
validate do |form|
|
40
40
|
if !block.call(form)
|
41
|
-
|
42
|
-
|
41
|
+
entity_name = self.class.superclass.to_s.tableize.split('/').last.singularize
|
42
|
+
full_key = "#{entity_name}.errors.#{key}"
|
43
|
+
form.add_error_key(field, full_key)
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|
@@ -76,8 +77,8 @@ module ApplicationForm
|
|
76
77
|
errors.details[:base].first[:error].to_s
|
77
78
|
end
|
78
79
|
|
79
|
-
def assign_attrs(
|
80
|
-
assign_attributes(
|
80
|
+
def assign_attrs(attributes)
|
81
|
+
assign_attributes(attributes)
|
81
82
|
self
|
82
83
|
end
|
83
84
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: application_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Mokevnin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-08-
|
12
|
+
date: 2021-08-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -77,12 +77,12 @@ files:
|
|
77
77
|
- lib/generators/application_form/USAGE
|
78
78
|
- lib/generators/application_form/form_generator.rb
|
79
79
|
- lib/generators/application_form/templates/form.rb
|
80
|
-
homepage: https://github.com/
|
80
|
+
homepage: https://github.com/rbbr-io/application_form
|
81
81
|
licenses:
|
82
82
|
- MIT
|
83
83
|
metadata:
|
84
|
-
homepage_uri: https://github.com/
|
85
|
-
source_code_uri: https://github.com/
|
84
|
+
homepage_uri: https://github.com/rbbr-io/application_form
|
85
|
+
source_code_uri: https://github.com/rbbr-io/application_form.git
|
86
86
|
post_install_message:
|
87
87
|
rdoc_options: []
|
88
88
|
require_paths:
|