valid_items 0.0.4 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +55 -0
- data/README.md +58 -0
- data/Rakefile +8 -0
- data/VERSION +1 -0
- data/lib/valid_items.rb +18 -9
- data/valid_items.gemspec +23 -0
- metadata +11 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a86c46b0ac4d5908b47494c3a1d56070157c43f7ad2e871a6846193da52a8c1c
|
4
|
+
data.tar.gz: 684cdc601ddf2974c4725ed1aaeba621fb63ca5fad31ec48ef5a6cd7181c0d51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ba4d8a619009657fafc8e5acf75125d65d97a3bb45a378ed9123515a6529ab8292be6b4a70042f9e8df50faba359c31f4c2629c54501dd220a0692368b81f9c
|
7
|
+
data.tar.gz: 25c4db1b95ae4cb455c9914d84d8a3846010d7f85a4910afa99f77c12f5012bfd476402bc86318d0e75c1f115855917b01f0266dd5e02232d19f8c2c4868144d
|
data/.gitignore
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# rdoc generated
|
2
|
+
rdoc
|
3
|
+
|
4
|
+
# yard generated
|
5
|
+
doc
|
6
|
+
.yardoc
|
7
|
+
|
8
|
+
developer.md
|
9
|
+
# bundler
|
10
|
+
.bundle
|
11
|
+
Gemfile.lock
|
12
|
+
Gemfile.local
|
13
|
+
*.gem
|
14
|
+
# rbenv
|
15
|
+
.ruby-version
|
16
|
+
|
17
|
+
|
18
|
+
# jeweler generated
|
19
|
+
pkg
|
20
|
+
|
21
|
+
# etags
|
22
|
+
TAGS
|
23
|
+
|
24
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
25
|
+
#
|
26
|
+
# * Create a file at ~/.gitignore
|
27
|
+
# * Include files you want ignored
|
28
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
29
|
+
#
|
30
|
+
# After doing this, these files will be ignored in all your git projects,
|
31
|
+
# saving you from having to 'pollute' every project you touch with them
|
32
|
+
#
|
33
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
34
|
+
#
|
35
|
+
# For MacOS:
|
36
|
+
#
|
37
|
+
#.DS_Store
|
38
|
+
|
39
|
+
# For TextMate
|
40
|
+
#*.tmproj
|
41
|
+
#tmtags
|
42
|
+
|
43
|
+
# For emacs:
|
44
|
+
#*~
|
45
|
+
#\#*
|
46
|
+
#.\#*
|
47
|
+
|
48
|
+
# For vim:
|
49
|
+
*.swp
|
50
|
+
|
51
|
+
# For redcar:
|
52
|
+
#.redcar
|
53
|
+
|
54
|
+
# For rubinius:
|
55
|
+
#*.rbc
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
Valid Items
|
2
|
+
=================
|
3
|
+
|
4
|
+
Goes through all your Rails ActiveRecord objects and check if they are all still pass your model validations. You may have added new validations to your model since creating your object, or ran update_column in your console to solve a production issue.
|
5
|
+
Inspired by a RailsConf talk by Ryan Laughlin and his talk at http://www.rofreg.com/talks/railsconf2018'
|
6
|
+
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
**ValidItem**'s installation is pretty standard:
|
11
|
+
|
12
|
+
```sh
|
13
|
+
$ gem install valid_items
|
14
|
+
```
|
15
|
+
|
16
|
+
If you'd rather install **ValidItem** using `bundler`, don't require it in your `Gemfile`:
|
17
|
+
|
18
|
+
```rb
|
19
|
+
gem 'valid_items', require: false
|
20
|
+
```
|
21
|
+
|
22
|
+
|
23
|
+
Example usage
|
24
|
+
-------------
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'valid_items'
|
28
|
+
ValidItems.checkup
|
29
|
+
=> User id 203: {:name=>["can't be blank"]}
|
30
|
+
```
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'valid_items'
|
34
|
+
ValidItems.checkup(email: 'example@example.com')
|
35
|
+
=> User id 203: {:name=>["can't be blank"]}
|
36
|
+
# and an email gets sent
|
37
|
+
```
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require 'valid_items'
|
41
|
+
ValidItems.checkup(updated_at: 1.day.ago)
|
42
|
+
=> 'ok'
|
43
|
+
```
|
44
|
+
|
45
|
+
|
46
|
+
```
|
47
|
+
Arguments:
|
48
|
+
email: (String)
|
49
|
+
updated_at: (ActiveSupport::TimeWithZone)
|
50
|
+
```
|
51
|
+
|
52
|
+
Running in development
|
53
|
+
----------------------
|
54
|
+
Eager Load is required on development, so that valid_items can query all AR models
|
55
|
+
```
|
56
|
+
Rails.application.eager_load!
|
57
|
+
```
|
58
|
+
You must have upgraded your Rails app so that all your models inherit from ApplicationRecord rather than ActiveRecord::Base.
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.11
|
data/lib/valid_items.rb
CHANGED
@@ -1,23 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rails/all'
|
3
|
+
|
4
|
+
unless Object.const_defined?('ApplicationRecord')
|
5
|
+
class ApplicationRecord < ActiveRecord::Base
|
6
|
+
self.abstract_class = true
|
7
|
+
end
|
4
8
|
end
|
9
|
+
|
5
10
|
class ValidItems
|
6
11
|
# Check that all your ActiveRecord Objects are still valid
|
7
12
|
#
|
8
13
|
# Example:
|
9
14
|
# >> ValidItems.checkup()
|
10
15
|
# => User id 203: {:name=>["can't be blank"]}
|
11
|
-
# >> ValidItems.checkup(
|
16
|
+
# >> ValidItems.checkup(email: 'example@example.com')
|
12
17
|
# => User id 203: {:name=>["can't be blank"]} and an email gets sent
|
13
18
|
# >> ValidItems.checkup(updated_at: 1.day.ago)
|
14
19
|
# => User id 203: {:name=>["can't be blank"]}
|
15
20
|
# Just want to check recent changes, in case of a large db
|
16
21
|
#
|
17
22
|
# Arguments:
|
18
|
-
#
|
23
|
+
# email: (String)
|
19
24
|
# updated_at: (ActiveSupport::TimeWithZone)
|
20
|
-
def self.checkup(
|
25
|
+
def self.checkup(email: nil, updated_at: 100.years.ago)
|
21
26
|
issues = []
|
22
27
|
ApplicationRecord.descendants.collect(&:name).each do |model|
|
23
28
|
model.constantize.where('updated_at > ?', updated_at).find_each do |item|
|
@@ -26,9 +31,13 @@ class ValidItems
|
|
26
31
|
end
|
27
32
|
return 'ok' if issues.blank?
|
28
33
|
|
29
|
-
if
|
30
|
-
mail(
|
31
|
-
|
34
|
+
if email.present?
|
35
|
+
ActionMailer::Base.mail(
|
36
|
+
from: email,
|
37
|
+
to: email,
|
38
|
+
subject: "DB Issues Discovered in #{Rails.env}",
|
39
|
+
body: issues.join("\r\n")
|
40
|
+
).deliver
|
32
41
|
end
|
33
42
|
puts issues
|
34
43
|
end
|
data/valid_items.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
version = File.read('VERSION').strip
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'valid_items'
|
6
|
+
s.version = version
|
7
|
+
s.date = '2018-05-31'
|
8
|
+
s.summary = 'Check that all your Rails ActiveRecord Objects still pass their model validations'
|
9
|
+
s.description = 'Goes through all your Rails ActiveRecord objects and check if they are all still pass your model validations. You may have added new validations to your model since creating your object, or ran update_column in your console to solve a production issue. Find issues in your db before others do. Inspired by a RailsConf talk by Ryan Laughlin and his talk at http://www.rofreg.com/talks/railsconf2018'
|
10
|
+
s.authors = ['Vinny Glennon']
|
11
|
+
s.email = 'vinnyglennon@gmail.com'
|
12
|
+
s.platform = Gem::Platform::RUBY
|
13
|
+
s.files = `git ls-files`.split($/)
|
14
|
+
s.test_files = s.files.grep(%r{^(test)/})
|
15
|
+
s.homepage = 'http://rubygems.org/gems/valid_items'
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.license = 'MIT'
|
18
|
+
s.required_ruby_version = '>= 1.9'
|
19
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
20
|
+
s.add_development_dependency 'rake', '~> 12.0'
|
21
|
+
s.add_development_dependency 'rubocop', '~> 0.50.0'
|
22
|
+
s.add_dependency 'rails', '>= 5', '< 6.0'
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valid_items
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vinny Glennon
|
@@ -39,12 +39,12 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.50.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '5'
|
48
48
|
- - "<"
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: '6.0'
|
@@ -52,29 +52,9 @@ dependencies:
|
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
|
-
- - "
|
55
|
+
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: '
|
58
|
-
- - "<"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '6.0'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: activerecord
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - ">"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '4.1'
|
68
|
-
- - "<"
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: '6.0'
|
71
|
-
type: :runtime
|
72
|
-
prerelease: false
|
73
|
-
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
requirements:
|
75
|
-
- - ">"
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '4.1'
|
57
|
+
version: '5'
|
78
58
|
- - "<"
|
79
59
|
- !ruby/object:Gem::Version
|
80
60
|
version: '6.0'
|
@@ -88,8 +68,13 @@ executables: []
|
|
88
68
|
extensions: []
|
89
69
|
extra_rdoc_files: []
|
90
70
|
files:
|
71
|
+
- ".gitignore"
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- VERSION
|
91
75
|
- lib/valid_items.rb
|
92
76
|
- test/test_valid_items.rb
|
77
|
+
- valid_items.gemspec
|
93
78
|
homepage: http://rubygems.org/gems/valid_items
|
94
79
|
licenses:
|
95
80
|
- MIT
|