lite-form 1.0.4 → 1.1.2

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: 222e3689b037e5b8f7ab55241b45510f871b7b6045c5a2f479e1369c1e684bfd
4
- data.tar.gz: adfe85542a0edca34677ef5cfcc9ca3078e40e3f29f88f921886d71c9ffd5540
3
+ metadata.gz: edc628150bb3048390184ee741156c9c8a445b05ab1b3a95159f187b0772b4c0
4
+ data.tar.gz: a36bddfb844f8a2b720250f7f0cffa86b45377470d321939d152285ab05c842f
5
5
  SHA512:
6
- metadata.gz: 3b4182e69c63b4f2cfe0cc27bfaa6c808997e3c07da2eee378c33ea1b2aefb27dec91188a7b11fc637edafddc66e6f1adfb4ba788aee77874b8a58e1eb41431e
7
- data.tar.gz: 2e50a501dee8928d9e93b3953ce534c11727a1ccb96a92e0a0323e92360301badbb15712316bc4568682a5923d90fe14972d4f65b14600ef603187b2602e663b
6
+ metadata.gz: 82bb7f8dcf0a43debc77d79288ea3d9c7406d3a23f99c255bd40a36046cc8fe7b998521831a0d9131dd06ad5b9b9d1189e9fee5dbc1982c99441d65675f6c10a
7
+ data.tar.gz: 81d9ad5f562f1f340ba2065cc4fef461d9f7f918514cef308e04987926543398a4b8882ed9a6188a7899b0f4ff172d4f5386316884bd3a8c4e7de5f1cfc0fcd6
data/.rubocop.yml CHANGED
@@ -1,10 +1,16 @@
1
1
  require:
2
2
  - rubocop-performance
3
+ - rubocop-rake
3
4
  - rubocop-rspec
4
5
  AllCops:
5
- TargetRubyVersion: 2.6
6
+ TargetRubyVersion: 3.0
7
+ NewCops: enable
6
8
  DisplayCopNames: true
7
9
  DisplayStyleGuide: true
10
+ Gemspec/RequiredRubyVersion:
11
+ Enabled: false
12
+ Layout/EmptyLinesAroundAttributeAccessor:
13
+ Enabled: true
8
14
  Layout/EmptyLinesAroundBlockBody:
9
15
  Exclude:
10
16
  - 'spec/**/**/*'
@@ -14,6 +20,12 @@ Layout/EmptyLinesAroundModuleBody:
14
20
  EnforcedStyle: empty_lines_except_namespace
15
21
  Layout/LineLength:
16
22
  Max: 100
23
+ Layout/SpaceAroundMethodCallOperator:
24
+ Enabled: true
25
+ Lint/RaiseException:
26
+ Enabled: true
27
+ Lint/StructNewOverride:
28
+ Enabled: true
17
29
  Metrics/BlockLength:
18
30
  Exclude:
19
31
  - 'spec/**/**/*'
@@ -24,6 +36,8 @@ RSpec/ExampleLength:
24
36
  Enabled: false
25
37
  RSpec/MultipleExpectations:
26
38
  Enabled: false
39
+ Style/ArgumentsForwarding:
40
+ Enabled: false
27
41
  Style/Documentation:
28
42
  Enabled: false
29
43
  Style/ExpandPathArguments:
data/.travis.yml CHANGED
@@ -4,6 +4,7 @@ cache: bundler
4
4
  rvm:
5
5
  - 2.5
6
6
  - 2.6
7
+ - 2.7
7
8
  - ruby-head
8
9
  matrix:
9
10
  fast_finish: true
data/CHANGELOG.md CHANGED
@@ -6,6 +6,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.1.2] - 2021-07-22
10
+ ### Changed
11
+ - Improved setup
12
+
13
+ ## [1.1.1] - 2021-07-21
14
+ ### Changed
15
+ - Improved Railtie support
16
+
17
+ ## [1.1.0] - 2021-07-19
18
+ ### Added
19
+ - Added Ruby 3.0 support
20
+
21
+ ## [1.0.5] - 2020-05-20
22
+ ### Added
23
+ - Added ruby 2.7 support
24
+ - Added save args
25
+ - Added more callback support
26
+ ### Removed
27
+ - Removed archive and destroy propagation
28
+
9
29
  ## [1.0.4] - 2019-12-21
10
30
  ### Removed
11
31
  - Removed generator empty directory check
data/Gemfile.lock CHANGED
@@ -1,65 +1,71 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-form (1.0.4)
4
+ lite-form (1.1.2)
5
5
  activemodel
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actionpack (6.0.2.1)
11
- actionview (= 6.0.2.1)
12
- activesupport (= 6.0.2.1)
13
- rack (~> 2.0, >= 2.0.8)
10
+ actionpack (6.1.4)
11
+ actionview (= 6.1.4)
12
+ activesupport (= 6.1.4)
13
+ rack (~> 2.0, >= 2.0.9)
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.2.1)
18
- activesupport (= 6.0.2.1)
17
+ actionview (6.1.4)
18
+ activesupport (= 6.1.4)
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.2.1)
24
- activesupport (= 6.0.2.1)
25
- activerecord (6.0.2.1)
26
- activemodel (= 6.0.2.1)
27
- activesupport (= 6.0.2.1)
28
- activesupport (6.0.2.1)
23
+ activemodel (6.1.4)
24
+ activesupport (= 6.1.4)
25
+ activerecord (6.1.4)
26
+ activemodel (= 6.1.4)
27
+ activesupport (= 6.1.4)
28
+ activesupport (6.1.4)
29
29
  concurrent-ruby (~> 1.0, >= 1.0.2)
30
- i18n (>= 0.7, < 2)
31
- minitest (~> 5.1)
32
- tzinfo (~> 1.1)
33
- zeitwerk (~> 2.2)
34
- ast (2.4.0)
30
+ i18n (>= 1.6, < 2)
31
+ minitest (>= 5.1)
32
+ tzinfo (~> 2.0)
33
+ zeitwerk (~> 2.3)
34
+ ast (2.4.2)
35
35
  builder (3.2.4)
36
36
  colorize (0.8.1)
37
- concurrent-ruby (1.1.5)
38
- crass (1.0.5)
39
- database_cleaner (1.7.0)
40
- diff-lcs (1.3)
41
- erubi (1.9.0)
42
- fasterer (0.8.1)
37
+ concurrent-ruby (1.1.9)
38
+ crass (1.0.6)
39
+ database_cleaner (2.0.1)
40
+ database_cleaner-active_record (~> 2.0.0)
41
+ database_cleaner-active_record (2.0.1)
42
+ activerecord (>= 5.a)
43
+ database_cleaner-core (~> 2.0.0)
44
+ database_cleaner-core (2.0.1)
45
+ diff-lcs (1.4.4)
46
+ erubi (1.10.0)
47
+ fasterer (0.9.0)
43
48
  colorize (~> 0.7)
44
49
  ruby_parser (>= 3.14.1)
45
50
  generator_spec (0.9.4)
46
51
  activesupport (>= 3.0.0)
47
52
  railties (>= 3.0.0)
48
- i18n (1.7.0)
53
+ i18n (1.8.10)
49
54
  concurrent-ruby (~> 1.0)
50
- jaro_winkler (1.5.4)
51
- loofah (2.4.0)
55
+ loofah (2.10.0)
52
56
  crass (~> 1.0.2)
53
57
  nokogiri (>= 1.5.9)
54
- method_source (0.9.2)
55
- mini_portile2 (2.4.0)
56
- minitest (5.13.0)
57
- nokogiri (1.10.7)
58
- mini_portile2 (~> 2.4.0)
59
- parallel (1.19.1)
60
- parser (2.6.5.0)
61
- ast (~> 2.4.0)
62
- rack (2.0.8)
58
+ method_source (1.0.0)
59
+ mini_portile2 (2.5.3)
60
+ minitest (5.14.4)
61
+ nokogiri (1.11.7)
62
+ mini_portile2 (~> 2.5.0)
63
+ racc (~> 1.4)
64
+ parallel (1.20.1)
65
+ parser (3.0.2.0)
66
+ ast (~> 2.4.1)
67
+ racc (1.5.2)
68
+ rack (2.2.3)
63
69
  rack-test (1.1.0)
64
70
  rack (>= 1.0, < 3)
65
71
  rails-dom-testing (2.0.3)
@@ -67,49 +73,58 @@ GEM
67
73
  nokogiri (>= 1.6)
68
74
  rails-html-sanitizer (1.3.0)
69
75
  loofah (~> 2.3)
70
- railties (6.0.2.1)
71
- actionpack (= 6.0.2.1)
72
- activesupport (= 6.0.2.1)
76
+ railties (6.1.4)
77
+ actionpack (= 6.1.4)
78
+ activesupport (= 6.1.4)
73
79
  method_source
74
- rake (>= 0.8.7)
75
- thor (>= 0.20.3, < 2.0)
80
+ rake (>= 0.13)
81
+ thor (~> 1.0)
76
82
  rainbow (3.0.0)
77
- rake (13.0.1)
78
- rspec (3.9.0)
79
- rspec-core (~> 3.9.0)
80
- rspec-expectations (~> 3.9.0)
81
- rspec-mocks (~> 3.9.0)
82
- rspec-core (3.9.0)
83
- rspec-support (~> 3.9.0)
84
- rspec-expectations (3.9.0)
83
+ rake (13.0.6)
84
+ regexp_parser (2.1.1)
85
+ rexml (3.2.5)
86
+ rspec (3.10.0)
87
+ rspec-core (~> 3.10.0)
88
+ rspec-expectations (~> 3.10.0)
89
+ rspec-mocks (~> 3.10.0)
90
+ rspec-core (3.10.1)
91
+ rspec-support (~> 3.10.0)
92
+ rspec-expectations (3.10.1)
85
93
  diff-lcs (>= 1.2.0, < 2.0)
86
- rspec-support (~> 3.9.0)
87
- rspec-mocks (3.9.0)
94
+ rspec-support (~> 3.10.0)
95
+ rspec-mocks (3.10.2)
88
96
  diff-lcs (>= 1.2.0, < 2.0)
89
- rspec-support (~> 3.9.0)
90
- rspec-support (3.9.0)
91
- rubocop (0.78.0)
92
- jaro_winkler (~> 1.5.1)
97
+ rspec-support (~> 3.10.0)
98
+ rspec-support (3.10.2)
99
+ rubocop (1.18.3)
93
100
  parallel (~> 1.10)
94
- parser (>= 2.6)
101
+ parser (>= 3.0.0.0)
95
102
  rainbow (>= 2.2.2, < 4.0)
103
+ regexp_parser (>= 1.8, < 3.0)
104
+ rexml
105
+ rubocop-ast (>= 1.7.0, < 2.0)
96
106
  ruby-progressbar (~> 1.7)
97
- unicode-display_width (>= 1.4.0, < 1.7)
98
- rubocop-performance (1.5.1)
99
- rubocop (>= 0.71.0)
100
- rubocop-rspec (1.37.1)
101
- rubocop (>= 0.68.1)
102
- ruby-progressbar (1.10.1)
103
- ruby_parser (3.14.1)
104
- sexp_processor (~> 4.9)
105
- sexp_processor (4.13.0)
107
+ unicode-display_width (>= 1.4.0, < 3.0)
108
+ rubocop-ast (1.8.0)
109
+ parser (>= 3.0.1.1)
110
+ rubocop-performance (1.11.4)
111
+ rubocop (>= 1.7.0, < 2.0)
112
+ rubocop-ast (>= 0.4.0)
113
+ rubocop-rake (0.6.0)
114
+ rubocop (~> 1.0)
115
+ rubocop-rspec (2.4.0)
116
+ rubocop (~> 1.0)
117
+ rubocop-ast (>= 1.1.0)
118
+ ruby-progressbar (1.11.0)
119
+ ruby_parser (3.16.0)
120
+ sexp_processor (~> 4.15, >= 4.15.1)
121
+ sexp_processor (4.15.3)
106
122
  sqlite3 (1.4.2)
107
- thor (1.0.1)
108
- thread_safe (0.3.6)
109
- tzinfo (1.2.5)
110
- thread_safe (~> 0.1)
111
- unicode-display_width (1.6.0)
112
- zeitwerk (2.2.2)
123
+ thor (1.1.0)
124
+ tzinfo (2.0.4)
125
+ concurrent-ruby (~> 1.0)
126
+ unicode-display_width (2.0.0)
127
+ zeitwerk (2.4.2)
113
128
 
114
129
  PLATFORMS
115
130
  ruby
@@ -125,8 +140,9 @@ DEPENDENCIES
125
140
  rspec
126
141
  rubocop
127
142
  rubocop-performance
143
+ rubocop-rake
128
144
  rubocop-rspec
129
145
  sqlite3
130
146
 
131
147
  BUNDLED WITH
132
- 2.0.2
148
+ 2.2.24
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 4 predefined callbacks to trigger before, after, and
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)`, `update_and_return!(object, params)`,
78
- # `save_and_return!(object)`, and `destroy_and_return!(object)`
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
- ActiveRecord::Base.transaction do
84
- user = User.find(attributes[:id])
85
- update_and_return!(user, attributes.slice(:id))
86
- update_and_return!(user.settings, tour: false)
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
  ```
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails/generators'
4
-
5
3
  module Rails
6
4
  class FormGenerator < Rails::Generators::NamedBase
7
5
 
data/lib/lite/form.rb CHANGED
@@ -1,14 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_model'
4
- require 'lite/form/version'
5
-
6
- %w[propagation persistence errors].each do |name|
7
- require "lite/form/helpers/#{name}"
8
- end
3
+ require 'active_model' unless defined?(ActiveModel)
9
4
 
10
- %w[exceptions states base].each do |name|
11
- require "lite/form/#{name}"
12
- end
5
+ require 'generators/rails/form_generator' if defined?(Rails::Generators)
13
6
 
14
- require 'generators/rails/form_generator'
7
+ require 'lite/form/version'
8
+ require 'lite/form/helpers/propagation'
9
+ require 'lite/form/helpers/persistence'
10
+ require 'lite/form/helpers/errors'
11
+ require 'lite/form/exceptions'
12
+ require 'lite/form/states'
13
+ require 'lite/form/base'
@@ -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
@@ -50,6 +50,11 @@ module Lite
50
50
  errors.empty?
51
51
  end
52
52
 
53
+ def raise_transaction_rollback(exception)
54
+ run_callbacks(:rollback)
55
+ raise exception
56
+ end
57
+
53
58
  end
54
59
  end
55
60
  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
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Form
5
5
 
6
- VERSION ||= '1.0.4'
6
+ VERSION = '1.1.2'
7
7
 
8
8
  end
9
9
  end
data/lite-form.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  )
26
26
  else
27
27
  raise 'RubyGems 2.0 or newer is required to protect against ' \
28
- 'public gem pushes.'
28
+ 'public gem pushes.'
29
29
  end
30
30
 
31
31
  # Specify which files should be added to the gem when it is released.
@@ -48,6 +48,7 @@ Gem::Specification.new do |spec|
48
48
  spec.add_development_dependency 'rspec'
49
49
  spec.add_development_dependency 'rubocop'
50
50
  spec.add_development_dependency 'rubocop-performance'
51
+ spec.add_development_dependency 'rubocop-rake'
51
52
  spec.add_development_dependency 'rubocop-rspec'
52
53
  spec.add_development_dependency 'sqlite3'
53
54
  end
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
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-21 00:00:00.000000000 Z
11
+ date: 2021-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rake
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: rubocop-rspec
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -178,7 +192,7 @@ dependencies:
178
192
  - - ">="
179
193
  - !ruby/object:Gem::Version
180
194
  version: '0'
181
- description:
195
+ description:
182
196
  email:
183
197
  - j.gomez@drexed.com
184
198
  executables: []
@@ -216,7 +230,7 @@ homepage: http://drexed.github.io/lite-form
216
230
  licenses:
217
231
  - MIT
218
232
  metadata: {}
219
- post_install_message:
233
+ post_install_message:
220
234
  rdoc_options: []
221
235
  require_paths:
222
236
  - lib
@@ -231,8 +245,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
245
  - !ruby/object:Gem::Version
232
246
  version: '0'
233
247
  requirements: []
234
- rubygems_version: 3.1.1
235
- signing_key:
248
+ rubygems_version: 3.2.24
249
+ signing_key:
236
250
  specification_version: 4
237
251
  summary: Ruby Form based framework (aka form objects)
238
252
  test_files: []