active_form_model 0.1.0 → 0.2.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5137b6aa0942b3579c267727c5931e301685315538434fae74b11163f00cd294
|
4
|
+
data.tar.gz: 9cbd8454a8d71115b9cd16ea36e70fae3d5fd36ef31be1db60582bab31e11c46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcf09ef8ca148879c592559f75dc61ef682231ab20e405a8e948067aa7380635b56163378fcf0320d330760174494ca98a13b5db357e555c03bc041cc58b13d1
|
7
|
+
data.tar.gz: 8e920323d9e7f3b2bc3df89fcb31f7cb50eacf8294a7c74a17fa6910a07341f6be1c4e73bb3afb9355b29b713285028656b1144cf493065275bb372fc5a34a40
|
data/README.md
CHANGED
@@ -29,6 +29,16 @@ Or install it yourself as:
|
|
29
29
|
1. Add permitted params inside the class
|
30
30
|
1. Use it as a normal model (without strong_params)
|
31
31
|
|
32
|
+
## Generator
|
33
|
+
|
34
|
+
Use the supplied generator to generate forms:
|
35
|
+
|
36
|
+
$ rails g active_form_model:form sign_up --model=user
|
37
|
+
|
38
|
+
or with namespace model
|
39
|
+
|
40
|
+
$ rails g active_form_model:form admin_post --model=blog/post
|
41
|
+
|
32
42
|
### Example
|
33
43
|
|
34
44
|
```ruby
|
@@ -41,7 +51,7 @@ class UserSignUpForm < User
|
|
41
51
|
|
42
52
|
# add validation if necessary
|
43
53
|
# they will be merged with base class' validation
|
44
|
-
|
54
|
+
validates :password, presence: true
|
45
55
|
|
46
56
|
# optional data normalization
|
47
57
|
def email=(email)
|
@@ -54,6 +64,13 @@ class UserSignUpForm < User
|
|
54
64
|
end
|
55
65
|
```
|
56
66
|
|
67
|
+
In some cases it is necessary to use ActiveRecord object directly without form. For such cases conveniently to use method `become()` (built-in ActiveRecord):
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
user = User.find(params[:id])
|
71
|
+
form = user.becomes(UserSignUpForm)
|
72
|
+
```
|
73
|
+
|
57
74
|
## Development
|
58
75
|
|
59
76
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveFormModel
|
4
|
+
module Generators
|
5
|
+
class FormGenerator < ::Rails::Generators::NamedBase
|
6
|
+
class_option :model, type: :string
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
8
|
+
|
9
|
+
def create_form
|
10
|
+
template 'form.rb', File.join('app/forms', class_path, "#{file_name}_form.rb")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_form_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Based on inheritance
|
14
14
|
email:
|
@@ -30,6 +30,9 @@ files:
|
|
30
30
|
- bin/setup
|
31
31
|
- lib/active_form_model.rb
|
32
32
|
- lib/active_form_model/version.rb
|
33
|
+
- lib/generators/active_form_model/USAGE
|
34
|
+
- lib/generators/active_form_model/form_generator.rb
|
35
|
+
- lib/generators/active_form_model/templates/form.rb
|
33
36
|
homepage: https://github.com/Hexlet/active_form_model
|
34
37
|
licenses:
|
35
38
|
- MIT
|