validation_errors 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8679caa07860e4574fa21e0ebe978a31405fadb47f5c2ec9bae0b5d2f801e349
4
+ data.tar.gz: a5d24ff1ee7c2f2a5f0aea3c0068cb60b2c8467f20f99c67ad57f0a292d0f877
5
+ SHA512:
6
+ metadata.gz: 1e7b20f0989065c49e2f7d42723f962e122e1a899248e1544f0e487bf5e9f4a458b8eea058c94cbeedc5ccacd893a26b8cb041687aed0301fd8e9b40934188d1
7
+ data.tar.gz: 24d4b7c52ba5a8514a1583f875124c511bcb9107164cc2c061dfecc33cb6b8c9f5edb06c96612ec661ed395efebe4b354788fa32f1c9a606577d7ee61b6e428c
@@ -0,0 +1,18 @@
1
+ version: v1.0
2
+ name: main-deploy
3
+ agent:
4
+ machine:
5
+ type: e1-standard-2
6
+ os_image: ubuntu1804
7
+
8
+ blocks:
9
+ - name: main-deploy
10
+ task:
11
+ secrets:
12
+ - name: rubygems-deploy
13
+ jobs:
14
+ - name: main-deploy
15
+ commands:
16
+ - checkout --use-cache
17
+ - gem build validation_errors
18
+ - gem push validation_errors-*.gem
@@ -0,0 +1,32 @@
1
+ version: "v1.0"
2
+ name: validation_errors
3
+ agent:
4
+ machine:
5
+ type: e1-standard-2
6
+ os_image: ubuntu1804
7
+ auto_cancel:
8
+ running:
9
+ when: "true"
10
+
11
+ blocks:
12
+ - name: tests
13
+ execution_time_limit:
14
+ minutes: 10
15
+ task:
16
+ secrets:
17
+ - name: validation_errors
18
+ prologue:
19
+ commands:
20
+ - checkout --use-cache
21
+ - cache restore
22
+ - bundle config set path 'vendor/bundle'
23
+ - bundle install -j 4
24
+ - cache store
25
+ jobs:
26
+ - name: tests
27
+ commands:
28
+ - bundle exec standardrb
29
+ - bundle exec rake
30
+ promotions:
31
+ - name: main
32
+ pipeline_file: main-deploy.yml
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 2.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-09-19
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at coorasse@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in validation_errors.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ validation_errors (0.1.0)
5
+ activerecord (>= 4.1.0)
6
+ zeitwerk (>= 2.0.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (7.0.4)
12
+ activesupport (= 7.0.4)
13
+ activerecord (7.0.4)
14
+ activemodel (= 7.0.4)
15
+ activesupport (= 7.0.4)
16
+ activesupport (7.0.4)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ tzinfo (~> 2.0)
21
+ ast (2.4.2)
22
+ concurrent-ruby (1.1.10)
23
+ i18n (1.12.0)
24
+ concurrent-ruby (~> 1.0)
25
+ minitest (5.16.3)
26
+ parallel (1.22.1)
27
+ parser (3.1.2.1)
28
+ ast (~> 2.4.1)
29
+ rainbow (3.1.1)
30
+ rake (13.0.6)
31
+ regexp_parser (2.5.0)
32
+ rexml (3.2.5)
33
+ rubocop (1.10.0)
34
+ parallel (~> 1.10)
35
+ parser (>= 3.0.0.0)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ regexp_parser (>= 1.8, < 3.0)
38
+ rexml
39
+ rubocop-ast (>= 1.2.0, < 2.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 1.4.0, < 3.0)
42
+ rubocop-ast (1.21.0)
43
+ parser (>= 3.1.1.0)
44
+ rubocop-performance (1.9.2)
45
+ rubocop (>= 0.90.0, < 2.0)
46
+ rubocop-ast (>= 0.4.0)
47
+ ruby-progressbar (1.11.0)
48
+ sqlite3 (1.5.0-arm64-darwin)
49
+ standard (0.13.0)
50
+ rubocop (= 1.10.0)
51
+ rubocop-performance (= 1.9.2)
52
+ tzinfo (2.0.5)
53
+ concurrent-ruby (~> 1.0)
54
+ unicode-display_width (2.3.0)
55
+ zeitwerk (2.6.0)
56
+
57
+ PLATFORMS
58
+ arm64-darwin-21
59
+
60
+ DEPENDENCIES
61
+ minitest (~> 5.0)
62
+ rake (~> 13.0)
63
+ sqlite3 (~> 1.5.0)
64
+ standard (~> 0.13.0)
65
+ validation_errors!
66
+
67
+ BUNDLED WITH
68
+ 2.3.21
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Alessandro Rodi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,205 @@
1
+ # ValidationErrors 😱
2
+
3
+ _Because shit happens_
4
+
5
+ This gem helps you keep track of the ActiveRecord validation errors that have been triggered on a model.
6
+
7
+ It persists them on a `validation_errors` database table the following information:
8
+ * time of the error
9
+ * model name
10
+ * model id (if available)
11
+ * action (create/update)
12
+ * errors.details (hash)
13
+
14
+ ## Why?
15
+
16
+ Validation errors happen. In some applications it might be interesting to keep track of them.
17
+ This gem has been extracted from various Ruby On Rails apps where I had this need.
18
+
19
+ If you have a validation error, you want to keep track of it...but how?
20
+ * You can use a logger, but then you have to parse the logs to get the information you need. i.e. is not structured.
21
+ * You can use an error tracker, like Sentry, but this isn't really an error, is it? If you have many, it might pollute your errors tracker.
22
+ * You can use a database table, and that's what this gem does.
23
+
24
+ This gem will keep track of the errors, and give you all the freedom to query it and extract statistics and make analysis.
25
+ By analysing from time to time these data, you might found out the following:
26
+ * Your UI sucks
27
+ * Your validations are too strict
28
+ * Your validations are too loose
29
+ * Your client-side validations are not working
30
+ * Your client-side validations are too loose
31
+ * This bullet point list has been generated by copilot
32
+
33
+ ## Installation
34
+
35
+ Install the gem and add it to the application's Gemfile by executing:
36
+
37
+ $ bundle add validation_errors
38
+
39
+ If bundler is not being used to manage dependencies, install the gem by executing:
40
+
41
+ $ gem install validation_errors
42
+
43
+ ## Usage
44
+
45
+ Run `bin/rails g validation_errors:install` to create the migration.
46
+ Stop evil spring, if the generator is not found: `spring stop`.
47
+
48
+ Run `bin/rails db:migrate` to create the tables.
49
+
50
+ The migration will create a `validation_errors` table. Check the migration for details.
51
+ If you use [Scenic](https://github.com/scenic-views/scenic) it will also generate some useful views.
52
+
53
+ ### Manual
54
+
55
+ You can now manually track errors by calling `ValidationErrors.track`:
56
+
57
+ ```ruby
58
+ ValidationErrors.track(your_invalid_model)
59
+ ```
60
+
61
+ An example could be the following:
62
+
63
+ ```ruby
64
+ def create
65
+ @user = User.new(user_params)
66
+ if @user.save
67
+ redirect_to @user
68
+ else
69
+ ValidationError.track(@user)
70
+ render :new
71
+ end
72
+ end
73
+ ```
74
+
75
+ Yes, this will execute an additinoal INSERT into your database. Keep it in mind.
76
+
77
+ ### Automatic
78
+
79
+ You can also track validation errors automatically by adding `track_validation_errors` in your model.
80
+
81
+ ```ruby
82
+ class User < ApplicationRecord
83
+ track_validation_errors
84
+ end
85
+ ```
86
+
87
+ by doing so, validation errors are tracked automatically on each `save`, `save!`, `update`, or `update!` call on your model.
88
+
89
+ ### Global
90
+
91
+ You can of course enable it on all you models by specifying it in ApplicationRecord directly:
92
+
93
+ ```ruby
94
+ class ApplicationRecord < ActiveRecord::Base
95
+ self.abstract_class = true
96
+ track_validation_errors
97
+ end
98
+ ```
99
+
100
+ We currently don't support (PR welcome):
101
+ * enable globally and disable on a specific model `skip_track_validation_errors`
102
+ * enable only for specific actions `track_validation_errors only: [:create]`
103
+ * disable only for specific actions `track_validation_errors except: [:create]`
104
+ * enable only for bang or non-bang methods `track_validation_errors only_bang: true`, `track_validation_errors only_non_bang: true`
105
+
106
+
107
+ ## Query your data
108
+
109
+ Now that you have installed the gem and started tracking, let's take a look at how the data are persisted and how you can query them.
110
+ We store the errors in exactly the same format returned by ActiveRecord `errors.details`.
111
+
112
+ Given a book, that failed to save because of validation errors, you'll get the following:
113
+
114
+ | id | invalid_model_name | invalid_model_id | action | details |
115
+ |----|--------------------|------------------|--------|-------------------------------------------------------------------------------------------------------|
116
+ | 1 | Book | 1 | create | `{ "base" => [{ "error" => "invalid" }], "title" => [{ "error" => "blank" }, {"error" => "invalid"}] }` |
117
+
118
+ The following SQL (Postgres only!) can be used to obtain a flattened view.
119
+ You can use it in your queries, or create a database view:
120
+
121
+ ```sql
122
+ select validation_errors.invalid_model_name,
123
+ validation_errors.invalid_model_id,
124
+ validation_errors.action,
125
+ validation_errors.created_at,
126
+ json_data.key as error_column,
127
+ json_array_elements(json_data.value)->>'error' as error_type
128
+ from validation_errors, json_each(validation_errors.details) as json_data
129
+ ```
130
+
131
+ **The gem will already create this view for you, if you use [Scenic](https://github.com/scenic-views/scenic).**
132
+
133
+ The result is the following:
134
+
135
+ | invalid_model_name | invalid_model_id | action | error_column | error_type |
136
+ |--------------------|------------------|--------|--------------|------------|
137
+ | Book | 1 | create | base | invalid |
138
+ | Book | 1 | create | title | blank |
139
+ | Book | 1 | create | title | invalid |
140
+
141
+
142
+ Let's now check some useful queries:
143
+
144
+ ### Count the number of errors per day
145
+
146
+ ```sql
147
+ select count(*), date(created_at)
148
+ from validation_errors
149
+ group by date(created_at)
150
+ order by date(created_at) desc;
151
+ ```
152
+
153
+ Please use [groupdate](https://github.com/ankane/groupdate) for more reliable results when grouping by date.
154
+
155
+ ```ruby
156
+ ValidationError.group_by_day(:created_at).count
157
+ ```
158
+
159
+ ### Count the number of errors per model and attribute
160
+
161
+ ```sql
162
+ select validation_errors.invalid_model_name,
163
+ json_data.key as error_column,
164
+ json_array_elements(json_data.value)->>'error' as error_type,
165
+ count(*)
166
+ from validation_errors,
167
+ json_each(validation_errors.details) as json_data
168
+ group by 1, 2, 3
169
+ order by 4 desc
170
+ ```
171
+
172
+ or, if you have the view above:
173
+
174
+ ```sql
175
+ select invalid_model_name, error_column, count(*)
176
+ from validation_errors_flat
177
+ group by 1, 2
178
+ ```
179
+
180
+ ```ruby
181
+ FlatValidationError.group(:invalid_model_name, :error_column).count
182
+ ```
183
+
184
+ ## Development
185
+
186
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
187
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
188
+
189
+ To install this gem onto your local machine, run `bundle exec rake install`.
190
+
191
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
192
+ which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
193
+
194
+ ## Contributing
195
+
196
+ Bug reports and pull requests are welcome on GitHub at https://github.com/coorasse/validation_errors.
197
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/coorasse/validation_errors/blob/master/CODE_OF_CONDUCT.md).
198
+
199
+ ## License
200
+
201
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
202
+
203
+ ## Code of Conduct
204
+
205
+ Everyone interacting in the ValidationErrors project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/coorasse/validation_errors/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "standard/rake"
13
+
14
+ task default: %i[test standard]
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FlatValidationError < ActiveRecord::Base
4
+ def readonly?
5
+ true
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class CreateFlatValidationErrors < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
+ def change
3
+ create_view :flat_validation_errors
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ class CreateValidationErrorsTable < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
+ def change
3
+ create_table :validation_errors do |t|
4
+ t.string :invalid_model_name, index: true
5
+ t.bigint :invalid_model_id
6
+ t.string :action, index: true
7
+ t.json :details
8
+ t.timestamps null: false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ select validation_errors.invalid_model_name,
2
+ validation_errors.invalid_model_id,
3
+ validation_errors.action,
4
+ validation_errors.created_at,
5
+ json_data.key as error_column,
6
+ json_array_elements(json_data.value)->>'error' as error_type
7
+ from validation_errors, json_each(validation_errors.details) as json_data
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/base"
4
+ require "rails/generators/migration"
5
+
6
+ module ValidationErrors
7
+ module Generators
8
+ class InstallGenerator < Rails::Generators::Base
9
+ include Rails::Generators::Migration
10
+
11
+ source_root File.expand_path("../../templates", __FILE__)
12
+
13
+ # Implement the required interface for Rails::Generators::Migration.
14
+ def self.next_migration_number(dirname)
15
+ next_migration_number = current_migration_number(dirname) + 1
16
+ ActiveRecord::Migration.next_migration_number(next_migration_number)
17
+ end
18
+
19
+ desc "Copy migrations to your application."
20
+ def copy_migrations
21
+ migration_template "create_validation_errors_table.rb", "db/migrate/create_validation_errors_table.rb"
22
+ if defined?(Scenic)
23
+ migration_template "create_flat_validation_errors.rb", "db/migrate/create_flat_validation_errors.rb"
24
+ copy_file "flat_validation_errors_v01.sql", "db/views/flat_validation_errors_v01.sql"
25
+ else
26
+ puts "Scenic is not installed so we will skip the creation of the flat_validation_errors view.\nCheck the README for more information."
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ValidationError < ActiveRecord::Base
4
+ def self.track(invalid_model)
5
+ create!(invalid_model_name: invalid_model.class.name,
6
+ invalid_model_id: invalid_model.id,
7
+ details: invalid_model.errors.details,
8
+ action: invalid_model.persisted? ? "update" : "create")
9
+ end
10
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_record"
4
+ require "zeitwerk"
5
+
6
+ loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
7
+ loader.collapse("#{__dir__}/validation_errors")
8
+ loader.ignore("#{__dir__}/generators")
9
+ loader.setup
10
+
11
+ module ValidationErrors
12
+ module Trackable
13
+ def self.included(base)
14
+ base.extend ClassMethods
15
+ end
16
+
17
+ # :nodoc:
18
+ module ClassMethods
19
+ def track_validation_errors
20
+ include InstanceMethods
21
+ end
22
+ end
23
+
24
+ module InstanceMethods
25
+ def save(**options)
26
+ super.tap do |result|
27
+ ValidationError.track(self) unless result
28
+ end
29
+ end
30
+
31
+ # Attempts to save the record just like {ActiveRecord::Base#save}[rdoc-ref:Base#save] but
32
+ # will raise an ActiveRecord::RecordInvalid exception instead of returning +false+ if the record is not valid.
33
+ def save!(**options)
34
+ super
35
+ rescue ActiveRecord::RecordInvalid
36
+ ValidationError.track(self)
37
+ raise
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ ActiveRecord::Base.include ValidationErrors::Trackable
@@ -0,0 +1,20 @@
1
+ class ValidationErrors < ActiveRecord::Base
2
+ def self.track: (untyped invalid_model) -> untyped
3
+
4
+ module Trackable
5
+ def self.included: (untyped base) -> untyped
6
+
7
+ # :nodoc:
8
+ module ClassMethods
9
+ def track_validation_errors: () -> untyped
10
+ end
11
+
12
+ module InstanceMethods
13
+ def save: (**untyped options) -> untyped
14
+
15
+ # Attempts to save the record just like {ActiveRecord::Base#save}[rdoc-ref:Base#save] but
16
+ # will raise an ActiveRecord::RecordInvalid exception instead of returning +false+ if the record is not valid.
17
+ def save!: (**untyped options) -> untyped
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ module ValidationErrors
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: validation_errors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alessandro Rodi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: zeitwerk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.5.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.5.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: standard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.13.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.13.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '13.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '13.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.0'
97
+ description: Easily track all the validation errors on your database so that you can
98
+ analyse them.
99
+ email:
100
+ - rodi@hey.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".semaphore/main-deploy.yml"
106
+ - ".semaphore/semaphore.yml"
107
+ - ".standard.yml"
108
+ - CHANGELOG.md
109
+ - CODE_OF_CONDUCT.md
110
+ - Gemfile
111
+ - Gemfile.lock
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - lib/flat_validation_error.rb
116
+ - lib/generators/templates/create_flat_validation_errors.rb.tt
117
+ - lib/generators/templates/create_validation_errors_table.rb.tt
118
+ - lib/generators/templates/flat_validation_errors_v01.sql.tt
119
+ - lib/generators/validation_errors/install_generator.rb
120
+ - lib/validation_error.rb
121
+ - lib/validation_errors.rb
122
+ - sig/lib/validation_errors.rbs
123
+ - sig/validation_errors.rbs
124
+ homepage: https://github.com/coorasse/validation_errors
125
+ licenses:
126
+ - MIT
127
+ metadata:
128
+ homepage_uri: https://github.com/coorasse/validation_errors
129
+ source_code_uri: https://github.com/coorasse/validation_errors
130
+ changelog_uri: https://github.com/coorasse/validation_errors/blob/main/CHANGELOG.md
131
+ funding_uri: https://github.com/sponsors/coorasse
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: 2.6.0
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubygems_version: 3.3.10
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Track ActiveRecord validation errors on database
151
+ test_files: []