active_form_model 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a3ec45dd42ca3d0d4ae011c34429818ec18c16a359187085f6f49fb0717ee52
4
- data.tar.gz: f447db38cbdbf622c7b299c9b35e1bd824bf5f5a66e91452d3aa9a1a1c7caebe
3
+ metadata.gz: 5137b6aa0942b3579c267727c5931e301685315538434fae74b11163f00cd294
4
+ data.tar.gz: 9cbd8454a8d71115b9cd16ea36e70fae3d5fd36ef31be1db60582bab31e11c46
5
5
  SHA512:
6
- metadata.gz: c85a07da23cea7e5c441e56229ac5275459df8b7801222b828006b98a47632af22cb370ee7e0166492ee4dc4f21b7594c61535083ce5c564bcaa55527f735ce5
7
- data.tar.gz: 315f969ac8959dda763644409b0323b717a326fd682134d960a3238b35580a6a0ea0bc7a9ee3775af564fa9c0dfe7c63fb0b59222b0402a819eb64048f427031
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
- validate :password, presence: true
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.
@@ -1,3 +1,3 @@
1
1
  module ActiveFormModel
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates a form for a model with the given name.
3
+
4
+ Example:
5
+ rails generate active_form_model:form sign_up --model=user
6
+
7
+ This will create:
8
+ app/forms/user_form.rb
@@ -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
@@ -0,0 +1,5 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Form < <%= options['model'].classify %>
3
+ include ActiveFormModel
4
+ end
5
+ <% 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.1.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-06-22 00:00:00.000000000 Z
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