superform 0.3.0 → 0.4.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: b87df41698b91049bed9e30f976d56b92c5c694762a63803453d29fa47c025a9
4
- data.tar.gz: bd9ec4dd8499de8303411c3ee88f7a2888ce285b5592eb32829db6043782a4f9
3
+ metadata.gz: 764fb4731b8ae1977a1e05ce0410302e5f29f3c008c4e0326f9b3f852118cb37
4
+ data.tar.gz: 6d7887d4b7b3bbf2af8ebfe7e675a155061e4982231d3f52caefd7a5e4c4c85d
5
5
  SHA512:
6
- metadata.gz: 5f945ca1d2a57d3b4ac69d064c72f701cd7d3d524a64dd241c80a23b3fd53cecd572800f2ebbe760321348d0f770b60d60be5acb4a4482e007d9040d21b3898f
7
- data.tar.gz: a47df25dcc990f3162b874f85999df79e0acf170643395071aaa2b2c29fde23ff302a055a9ed132927945cc53c30376f645846370f5e323eb89115dc740136ce
6
+ metadata.gz: edb3acf775edcaacb269b0aff7200d6bfd22d2c5701eb7dd0c96149bbc515acf33b77f586809ac574520a4330c1ed1acbe304e8c54d60a2b219e28b72179321b
7
+ data.tar.gz: e2b69ed000da6eeddeb3a47f664abfe052bbd85ae0e5649d23131b134d5d68acc9032fd4660260207540724c5fa10b85d6c6b4609484849e7c480a9fbd90bae1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superform (0.2.0)
4
+ superform (0.4.0)
5
5
  phlex-rails (~> 1.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -144,14 +144,14 @@ Since Superforms are just Ruby objects, you can organize them however you want.
144
144
 
145
145
  ## Automatic strong parameters
146
146
 
147
- Guess what? Superform eliminates then need for Strong Parameters in Rails by assigning the values of the `params` hash _through_ your form. Here's what it looks like.
147
+ Guess what? Superform eliminates then need for Strong Parameters in Rails by assigning the values of the `params` hash _through_ your form via the `assign` method. Here's what it looks like.
148
148
 
149
149
  ```ruby
150
150
  class PostsController < ApplicationController
151
151
  include Superform::Rails::StrongParameters
152
152
 
153
153
  def create
154
- @post = assign params.require(:post), to: Post.new
154
+ @post = assign params.require(:post), to: Posts::Form.new(Post.new)
155
155
 
156
156
  if @post.save
157
157
  # Success path
@@ -163,7 +163,7 @@ class PostsController < ApplicationController
163
163
  def update
164
164
  @post = Post.find(params[:id])
165
165
 
166
- assign params.require(:post), to: @post
166
+ assign params.require(:post), to: Posts::Form.new(@post)
167
167
 
168
168
  if @post.save
169
169
  # Success path
@@ -171,14 +171,6 @@ class PostsController < ApplicationController
171
171
  # Error path
172
172
  end
173
173
  end
174
-
175
- private
176
- # Defaults to `Posts::Form`, but you can override it here if
177
- # you uncomment and add your own class. You could also pass the
178
- # `form: FormClass` into the `assign` method.
179
- #
180
- # def form_class
181
- # end
182
174
  end
183
175
  ```
184
176
 
@@ -102,20 +102,13 @@ module Superform
102
102
 
103
103
  module StrongParameters
104
104
  protected
105
- # Assigns params to the form model.
106
- def assign(params, to:, form: form_class)
107
- to.tap do |model|
108
- form.new(model).tap do |form|
109
- # TODO: Figure out how to render this in a way that doesn't concat a string; just throw everything away.
110
- render_to_string form
111
- form.assign params
112
- end
113
- end
114
- end
115
-
116
- # Defaults to the form defined in `./app/views/*/form.rb`.
117
- def form_class
118
- self.controller_name.camelize.constantize::Form
105
+ # Assigns params to the form and returns the model.
106
+ def assign(params, to:)
107
+ form = to
108
+ # TODO: Figure out how to render this in a way that doesn't concat a string; just throw everything away.
109
+ render_to_string form
110
+ form.assign params
111
+ form.model
119
112
  end
120
113
  end
121
114
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Superform
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-21 00:00:00.000000000 Z
11
+ date: 2023-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex-rails