lite-form 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +18 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +45 -45
- data/README.md +19 -9
- data/lib/lite/form/base.rb +8 -6
- data/lib/lite/form/helpers/errors.rb +5 -0
- data/lib/lite/form/helpers/propagation.rb +5 -7
- data/lib/lite/form/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f6348e50f8c224acb7db926a6e68cdaee3e317fae28c4976d775de547679c0c
|
4
|
+
data.tar.gz: de5fb7c924d72a17a3e7d75c09ec45a0c68b3d7ac3f0491398b62ae5df1ed416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '058745e0775a9d844551ae3df8913046cdb402bccfec011c089798c16ed5cee54c5bba3fa5368f8949d0ec1e13622365b9cc0945ced0301122b51f406c169b16'
|
7
|
+
data.tar.gz: e1538f82e2fdc246b9ff679bf304e7d5f5718c3127941381b3b7fd417405e5bdef3bd4d8f19583c404cf0bf8be5aa081f87be31420a15b2b07d5a7b14fbeeda9
|
data/.rubocop.yml
CHANGED
@@ -5,6 +5,8 @@ AllCops:
|
|
5
5
|
TargetRubyVersion: 2.6
|
6
6
|
DisplayCopNames: true
|
7
7
|
DisplayStyleGuide: true
|
8
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
9
|
+
Enabled: true
|
8
10
|
Layout/EmptyLinesAroundBlockBody:
|
9
11
|
Exclude:
|
10
12
|
- 'spec/**/**/*'
|
@@ -14,6 +16,12 @@ Layout/EmptyLinesAroundModuleBody:
|
|
14
16
|
EnforcedStyle: empty_lines_except_namespace
|
15
17
|
Layout/LineLength:
|
16
18
|
Max: 100
|
19
|
+
Layout/SpaceAroundMethodCallOperator:
|
20
|
+
Enabled: true
|
21
|
+
Lint/RaiseException:
|
22
|
+
Enabled: true
|
23
|
+
Lint/StructNewOverride:
|
24
|
+
Enabled: true
|
17
25
|
Metrics/BlockLength:
|
18
26
|
Exclude:
|
19
27
|
- 'spec/**/**/*'
|
@@ -28,3 +36,13 @@ Style/Documentation:
|
|
28
36
|
Enabled: false
|
29
37
|
Style/ExpandPathArguments:
|
30
38
|
Enabled: false
|
39
|
+
Style/ExponentialNotation:
|
40
|
+
Enabled: true
|
41
|
+
Style/HashEachMethods:
|
42
|
+
Enabled: true
|
43
|
+
Style/HashTransformKeys:
|
44
|
+
Enabled: true
|
45
|
+
Style/HashTransformValues:
|
46
|
+
Enabled: true
|
47
|
+
Style/SlicingWithRange:
|
48
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.0.5] - 2020-05-20
|
10
|
+
### Added
|
11
|
+
- Added save args
|
12
|
+
- Added more callback support
|
13
|
+
### Removed
|
14
|
+
- Removed archive and destroy propagation
|
15
|
+
|
9
16
|
## [1.0.4] - 2019-12-21
|
10
17
|
### Removed
|
11
18
|
- Removed generator empty directory check
|
data/Gemfile.lock
CHANGED
@@ -1,65 +1,64 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lite-form (1.0.
|
4
|
+
lite-form (1.0.5)
|
5
5
|
activemodel
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actionpack (6.0.
|
11
|
-
actionview (= 6.0.
|
12
|
-
activesupport (= 6.0.
|
10
|
+
actionpack (6.0.3.1)
|
11
|
+
actionview (= 6.0.3.1)
|
12
|
+
activesupport (= 6.0.3.1)
|
13
13
|
rack (~> 2.0, >= 2.0.8)
|
14
14
|
rack-test (>= 0.6.3)
|
15
15
|
rails-dom-testing (~> 2.0)
|
16
16
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
17
|
-
actionview (6.0.
|
18
|
-
activesupport (= 6.0.
|
17
|
+
actionview (6.0.3.1)
|
18
|
+
activesupport (= 6.0.3.1)
|
19
19
|
builder (~> 3.1)
|
20
20
|
erubi (~> 1.4)
|
21
21
|
rails-dom-testing (~> 2.0)
|
22
22
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
23
|
-
activemodel (6.0.
|
24
|
-
activesupport (= 6.0.
|
25
|
-
activerecord (6.0.
|
26
|
-
activemodel (= 6.0.
|
27
|
-
activesupport (= 6.0.
|
28
|
-
activesupport (6.0.
|
23
|
+
activemodel (6.0.3.1)
|
24
|
+
activesupport (= 6.0.3.1)
|
25
|
+
activerecord (6.0.3.1)
|
26
|
+
activemodel (= 6.0.3.1)
|
27
|
+
activesupport (= 6.0.3.1)
|
28
|
+
activesupport (6.0.3.1)
|
29
29
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
30
30
|
i18n (>= 0.7, < 2)
|
31
31
|
minitest (~> 5.1)
|
32
32
|
tzinfo (~> 1.1)
|
33
|
-
zeitwerk (~> 2.2)
|
33
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
34
34
|
ast (2.4.0)
|
35
35
|
builder (3.2.4)
|
36
36
|
colorize (0.8.1)
|
37
|
-
concurrent-ruby (1.1.
|
38
|
-
crass (1.0.
|
39
|
-
database_cleaner (1.
|
37
|
+
concurrent-ruby (1.1.6)
|
38
|
+
crass (1.0.6)
|
39
|
+
database_cleaner (1.8.5)
|
40
40
|
diff-lcs (1.3)
|
41
41
|
erubi (1.9.0)
|
42
|
-
fasterer (0.8.
|
42
|
+
fasterer (0.8.3)
|
43
43
|
colorize (~> 0.7)
|
44
44
|
ruby_parser (>= 3.14.1)
|
45
45
|
generator_spec (0.9.4)
|
46
46
|
activesupport (>= 3.0.0)
|
47
47
|
railties (>= 3.0.0)
|
48
|
-
i18n (1.
|
48
|
+
i18n (1.8.2)
|
49
49
|
concurrent-ruby (~> 1.0)
|
50
|
-
|
51
|
-
loofah (2.4.0)
|
50
|
+
loofah (2.5.0)
|
52
51
|
crass (~> 1.0.2)
|
53
52
|
nokogiri (>= 1.5.9)
|
54
|
-
method_source (0.
|
53
|
+
method_source (1.0.0)
|
55
54
|
mini_portile2 (2.4.0)
|
56
|
-
minitest (5.
|
57
|
-
nokogiri (1.10.
|
55
|
+
minitest (5.14.1)
|
56
|
+
nokogiri (1.10.9)
|
58
57
|
mini_portile2 (~> 2.4.0)
|
59
58
|
parallel (1.19.1)
|
60
|
-
parser (2.
|
59
|
+
parser (2.7.1.2)
|
61
60
|
ast (~> 2.4.0)
|
62
|
-
rack (2.
|
61
|
+
rack (2.2.2)
|
63
62
|
rack-test (1.1.0)
|
64
63
|
rack (>= 1.0, < 3)
|
65
64
|
rails-dom-testing (2.0.3)
|
@@ -67,49 +66,50 @@ GEM
|
|
67
66
|
nokogiri (>= 1.6)
|
68
67
|
rails-html-sanitizer (1.3.0)
|
69
68
|
loofah (~> 2.3)
|
70
|
-
railties (6.0.
|
71
|
-
actionpack (= 6.0.
|
72
|
-
activesupport (= 6.0.
|
69
|
+
railties (6.0.3.1)
|
70
|
+
actionpack (= 6.0.3.1)
|
71
|
+
activesupport (= 6.0.3.1)
|
73
72
|
method_source
|
74
73
|
rake (>= 0.8.7)
|
75
74
|
thor (>= 0.20.3, < 2.0)
|
76
75
|
rainbow (3.0.0)
|
77
76
|
rake (13.0.1)
|
77
|
+
rexml (3.2.4)
|
78
78
|
rspec (3.9.0)
|
79
79
|
rspec-core (~> 3.9.0)
|
80
80
|
rspec-expectations (~> 3.9.0)
|
81
81
|
rspec-mocks (~> 3.9.0)
|
82
|
-
rspec-core (3.9.
|
83
|
-
rspec-support (~> 3.9.
|
84
|
-
rspec-expectations (3.9.
|
82
|
+
rspec-core (3.9.2)
|
83
|
+
rspec-support (~> 3.9.3)
|
84
|
+
rspec-expectations (3.9.2)
|
85
85
|
diff-lcs (>= 1.2.0, < 2.0)
|
86
86
|
rspec-support (~> 3.9.0)
|
87
|
-
rspec-mocks (3.9.
|
87
|
+
rspec-mocks (3.9.1)
|
88
88
|
diff-lcs (>= 1.2.0, < 2.0)
|
89
89
|
rspec-support (~> 3.9.0)
|
90
|
-
rspec-support (3.9.
|
91
|
-
rubocop (0.
|
92
|
-
jaro_winkler (~> 1.5.1)
|
90
|
+
rspec-support (3.9.3)
|
91
|
+
rubocop (0.83.0)
|
93
92
|
parallel (~> 1.10)
|
94
|
-
parser (>= 2.
|
93
|
+
parser (>= 2.7.0.1)
|
95
94
|
rainbow (>= 2.2.2, < 4.0)
|
95
|
+
rexml
|
96
96
|
ruby-progressbar (~> 1.7)
|
97
|
-
unicode-display_width (>= 1.4.0, <
|
98
|
-
rubocop-performance (1.5.
|
97
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
98
|
+
rubocop-performance (1.5.2)
|
99
99
|
rubocop (>= 0.71.0)
|
100
|
-
rubocop-rspec (1.
|
100
|
+
rubocop-rspec (1.39.0)
|
101
101
|
rubocop (>= 0.68.1)
|
102
102
|
ruby-progressbar (1.10.1)
|
103
|
-
ruby_parser (3.14.
|
103
|
+
ruby_parser (3.14.2)
|
104
104
|
sexp_processor (~> 4.9)
|
105
|
-
sexp_processor (4.
|
105
|
+
sexp_processor (4.14.1)
|
106
106
|
sqlite3 (1.4.2)
|
107
107
|
thor (1.0.1)
|
108
108
|
thread_safe (0.3.6)
|
109
|
-
tzinfo (1.2.
|
109
|
+
tzinfo (1.2.7)
|
110
110
|
thread_safe (~> 0.1)
|
111
|
-
unicode-display_width (1.
|
112
|
-
zeitwerk (2.
|
111
|
+
unicode-display_width (1.7.0)
|
112
|
+
zeitwerk (2.3.0)
|
113
113
|
|
114
114
|
PLATFORMS
|
115
115
|
ruby
|
@@ -129,4 +129,4 @@ DEPENDENCIES
|
|
129
129
|
sqlite3
|
130
130
|
|
131
131
|
BUNDLED WITH
|
132
|
-
2.
|
132
|
+
2.1.4
|
data/README.md
CHANGED
@@ -59,9 +59,9 @@ class UserForm < ApplicationForm
|
|
59
59
|
# Setup your form validations like you would on model objects
|
60
60
|
validates :name, presence: true
|
61
61
|
|
62
|
-
# Access
|
62
|
+
# Access 6 predefined callbacks to trigger before, after, and
|
63
63
|
# around your actions. Available callbacks are `initialize`
|
64
|
-
# `create`, `save`, and `update
|
64
|
+
# `commit`, `create`, `rollback`, `save`, and `update`.
|
65
65
|
before_create :prepend_signature!
|
66
66
|
after_update :append_signature!
|
67
67
|
|
@@ -74,17 +74,26 @@ class UserForm < ApplicationForm
|
|
74
74
|
# Propagation methods help you perform an action on an object.
|
75
75
|
# If successful is returns the result else it adds the object
|
76
76
|
# errors to the form object. Available propagation methods are:
|
77
|
-
# `create_and_return!(object, params)`,
|
78
|
-
# `
|
77
|
+
# `create_and_return!(object, params)`,
|
78
|
+
# `update_and_return!(object, params)`,
|
79
|
+
# `save_and_return!(object)`
|
79
80
|
create_and_return!(User, attributes)
|
80
81
|
end
|
81
82
|
|
82
83
|
def update_action
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
run_callbacks(:commit) do
|
85
|
+
ActiveRecord::Base.transaction do
|
86
|
+
user = User.find(attributes[:id])
|
87
|
+
update_and_return!(user, attributes.slice(:id))
|
88
|
+
|
89
|
+
# The `save_and_return!` supports on/off validation
|
90
|
+
user.settings.web_notification = true
|
91
|
+
save_and_return!(user.settings, validate: false)
|
92
|
+
end
|
87
93
|
end
|
94
|
+
rescue StandardError => e
|
95
|
+
# This will run the `rollback` callback and re-raise the error.
|
96
|
+
raise_transaction_rollback(e)
|
88
97
|
end
|
89
98
|
|
90
99
|
def prepend_signature!
|
@@ -101,7 +110,6 @@ end
|
|
101
110
|
## Usage
|
102
111
|
|
103
112
|
To access the form you need to pass the object to the form class and thats it.
|
104
|
-
You can even decorate a collection of objects by passing the collection to `decorate`.
|
105
113
|
|
106
114
|
```ruby
|
107
115
|
form = UserForm.new(params)
|
@@ -139,7 +147,9 @@ include ActiveModel::Serialization
|
|
139
147
|
|
140
148
|
# Default callbacks that are defined
|
141
149
|
define_model_callbacks :initialize
|
150
|
+
define_model_callbacks :commit
|
142
151
|
define_model_callbacks :create
|
152
|
+
define_model_callbacks :rollback
|
143
153
|
define_model_callbacks :save
|
144
154
|
define_model_callbacks :update
|
145
155
|
```
|
data/lib/lite/form/base.rb
CHANGED
@@ -17,10 +17,18 @@ module Lite
|
|
17
17
|
include Lite::Form::Helpers::Propagation
|
18
18
|
|
19
19
|
define_model_callbacks :initialize
|
20
|
+
define_model_callbacks :commit
|
20
21
|
define_model_callbacks :create
|
22
|
+
define_model_callbacks :rollback
|
21
23
|
define_model_callbacks :save
|
22
24
|
define_model_callbacks :update
|
23
25
|
|
26
|
+
attr_reader :result
|
27
|
+
|
28
|
+
def initialize(params = {})
|
29
|
+
run_callbacks(:initialize) { super(params) }
|
30
|
+
end
|
31
|
+
|
24
32
|
class << self
|
25
33
|
|
26
34
|
def model_name
|
@@ -33,12 +41,6 @@ module Lite
|
|
33
41
|
|
34
42
|
end
|
35
43
|
|
36
|
-
attr_reader :result
|
37
|
-
|
38
|
-
def initialize(params = {})
|
39
|
-
run_callbacks(:initialize) { super(params) }
|
40
|
-
end
|
41
|
-
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
@@ -7,19 +7,17 @@ module Lite
|
|
7
7
|
|
8
8
|
private
|
9
9
|
|
10
|
-
%i[archive destroy save].each do |action|
|
11
|
-
define_method("#{action}_and_return!") do |klass|
|
12
|
-
merge_errors!(klass) unless klass.send(action)
|
13
|
-
klass
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
10
|
def create_and_return!(klass, params)
|
18
11
|
klass = klass.create(params)
|
19
12
|
merge_errors!(klass) unless klass.errors.empty?
|
20
13
|
klass
|
21
14
|
end
|
22
15
|
|
16
|
+
def save_and_return!(klass, *args)
|
17
|
+
merge_errors!(klass) unless klass.save(*args)
|
18
|
+
klass
|
19
|
+
end
|
20
|
+
|
23
21
|
def update_and_return!(klass, params)
|
24
22
|
merge_errors!(klass) unless klass.update(params)
|
25
23
|
klass
|
data/lib/lite/form/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lite-form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -231,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
231
231
|
- !ruby/object:Gem::Version
|
232
232
|
version: '0'
|
233
233
|
requirements: []
|
234
|
-
rubygems_version: 3.1.
|
234
|
+
rubygems_version: 3.1.3
|
235
235
|
signing_key:
|
236
236
|
specification_version: 4
|
237
237
|
summary: Ruby Form based framework (aka form objects)
|