yaaf 1.0.0 → 2.0.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/README.md +3 -3
- data/lib/yaaf/form.rb +21 -10
- data/lib/yaaf/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: feddd104fa95e89d35605eb65e7c6129f79bbd305e5f918f30a77b5e8c53a308
|
4
|
+
data.tar.gz: 5ef4e097af16ed57d978fda5ee5bf8591a38e1f7a6fc5d7fade748bae1a89605
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6ea16e280a8b17a4bb0a962eae22f08086012aea76109d99764cd220c2f07b52e25ba1664909eae1651609b0fd2c22785b81cd25dde6b4e945ce7e7ac267d71
|
7
|
+
data.tar.gz: 7683e9ff0bdfb4a3d15e7248652ee49b444c0c946b8c27d47f68abf4f66f2c529a0366472fea583c46696ba8b95deb5986ee395a4f8ea0a9a6ebcf813e1dc880
|
data/README.md
CHANGED
@@ -39,7 +39,7 @@ Form Objects is a design pattern that allows us to:
|
|
39
39
|
3. Keep business logic validations out of models
|
40
40
|
|
41
41
|
There are some other form objects gems but we felt none of them provided us all the features that we expected:
|
42
|
-
1. Form objects that
|
42
|
+
1. Form objects that behave like Rails models
|
43
43
|
2. Simple to use and to understand the implementation (no magic)
|
44
44
|
3. Easy to customize
|
45
45
|
4. Gem is well tested and maintained
|
@@ -50,7 +50,7 @@ If you want to learn more about Form Objects you can check out [these great arti
|
|
50
50
|
|
51
51
|
### Why YAAF?
|
52
52
|
|
53
|
-
- It is [
|
53
|
+
- It is [71 lines long](https://github.com/rootstrap/yaaf/blob/master/lib/yaaf/form.rb#L71). As you can imagine, we did no magic in such a few lines of code, we just leveraged Rails modules in order to provide our form objects with a Rails-like behavior. You can review the code, it's easy to understand.
|
54
54
|
|
55
55
|
- It provides a similar API to `ActiveModel` models so you can treat them interchangeably.
|
56
56
|
|
@@ -231,7 +231,7 @@ end
|
|
231
231
|
|
232
232
|
### Callbacks
|
233
233
|
|
234
|
-
`YAAF` form objects support
|
234
|
+
`YAAF` form objects support callbacks the same way as `ActiveModel` models. For example:
|
235
235
|
|
236
236
|
```ruby
|
237
237
|
class RegistrationForm < YAAF::Form
|
data/lib/yaaf/form.rb
CHANGED
@@ -8,30 +8,39 @@ module YAAF
|
|
8
8
|
include ::ActiveRecord::Transactions
|
9
9
|
define_model_callbacks :save
|
10
10
|
|
11
|
+
delegate :transaction, to: ::ActiveRecord::Base
|
12
|
+
|
11
13
|
validate :validate_models
|
12
14
|
|
13
15
|
def save(options = {})
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
run_callbacks :commit do
|
19
|
-
save_in_transaction(options)
|
20
|
-
end
|
16
|
+
save_form(options)
|
17
|
+
rescue ActiveRecord::RecordInvalid,
|
18
|
+
ActiveRecord::RecordNotSaved,
|
19
|
+
ActiveModel::ValidationError
|
21
20
|
|
22
|
-
|
21
|
+
false
|
23
22
|
end
|
24
23
|
|
25
24
|
def save!(options = {})
|
26
|
-
|
25
|
+
save_form(options)
|
27
26
|
end
|
28
27
|
|
29
28
|
private
|
30
29
|
|
31
30
|
attr_accessor :models
|
32
31
|
|
32
|
+
def save_form(options)
|
33
|
+
validate! unless options[:validate] == false
|
34
|
+
|
35
|
+
run_callbacks :commit do
|
36
|
+
save_in_transaction(options)
|
37
|
+
end
|
38
|
+
|
39
|
+
true
|
40
|
+
end
|
41
|
+
|
33
42
|
def save_in_transaction(options)
|
34
|
-
|
43
|
+
transaction do
|
35
44
|
run_callbacks :save do
|
36
45
|
save_models(options)
|
37
46
|
end
|
@@ -41,6 +50,8 @@ module YAAF
|
|
41
50
|
end
|
42
51
|
|
43
52
|
def save_models(options)
|
53
|
+
options.merge!(validate: false)
|
54
|
+
|
44
55
|
models.map { |model| model.save!(options) }
|
45
56
|
end
|
46
57
|
|
data/lib/yaaf/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaaf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Manuel Ramallo
|
8
8
|
- Santiago Bartesaghi
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -149,7 +149,7 @@ dependencies:
|
|
149
149
|
- - "~>"
|
150
150
|
- !ruby/object:Gem::Version
|
151
151
|
version: 1.4.2
|
152
|
-
description:
|
152
|
+
description:
|
153
153
|
email:
|
154
154
|
- juan.ramallo@rootstrap.com
|
155
155
|
executables: []
|
@@ -167,7 +167,7 @@ licenses:
|
|
167
167
|
metadata:
|
168
168
|
homepage_uri: https://github.com/rootstrap/yaaf
|
169
169
|
source_code_uri: https://github.com/rootstrap/yaaf
|
170
|
-
post_install_message:
|
170
|
+
post_install_message:
|
171
171
|
rdoc_options: []
|
172
172
|
require_paths:
|
173
173
|
- lib
|
@@ -182,8 +182,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
182
|
- !ruby/object:Gem::Version
|
183
183
|
version: '0'
|
184
184
|
requirements: []
|
185
|
-
rubygems_version: 3.
|
186
|
-
signing_key:
|
185
|
+
rubygems_version: 3.0.3
|
186
|
+
signing_key:
|
187
187
|
specification_version: 4
|
188
188
|
summary: Easing the form object pattern in Rails applications.
|
189
189
|
test_files: []
|