valid_items 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/valid_items.rb +35 -0
- data/test/test_valid_items.rb +8 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0bcd92760474c26d012a5c31b37cb539f12c7cdbd15f962551fc9d56a66bb8bc
|
4
|
+
data.tar.gz: 24b7f731c030a5aa187b0d9ab3f84a848fb351c72ea120a42eb2ef38939cfe71
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2a8f7e5c1cac64cbfdf83f2443ff3069728c5347176a2a427603559968ca67b9273e5d48abfa2e34b2163dac1672e3b8206e8cce1187f4e2e611386a872f57bd
|
7
|
+
data.tar.gz: 3dd1b927af42e8452251da7b19ccce00d8afb5ebf599fc1bfb69c045e1b47fcd10174db53c70202fe2441e5da18375e0e496662907063d8993e5828c325ea0c8
|
data/lib/valid_items.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
class ApplicationRecord < ActiveRecord::Base
|
3
|
+
self.abstract_class = true
|
4
|
+
end
|
5
|
+
class ValidItems
|
6
|
+
# Check that all your ActiveRecord Objects are still valid
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
# >> ValidItems.checkup()
|
10
|
+
# => User id 203: {:name=>["can't be blank"]}
|
11
|
+
# >> ValidItems.checkup(email_report: 'example@example.com')
|
12
|
+
# => User id 203: {:name=>["can't be blank"]} and an email gets sent
|
13
|
+
# >> ValidItems.checkup(updated_at: 1.day.ago)
|
14
|
+
# => User id 203: {:name=>["can't be blank"]}
|
15
|
+
# Just want to check recent changes, in case of a large db
|
16
|
+
#
|
17
|
+
# Arguments:
|
18
|
+
# email_report: (String)
|
19
|
+
# updated_at: (ActiveSupport::TimeWithZone)
|
20
|
+
def self.checkup(email_report: nil, updated_at: 100.years.ago)
|
21
|
+
issues = []
|
22
|
+
ApplicationRecord.descendants.collect(&:name).each do |model|
|
23
|
+
model.constantize.where('updated_at > ?', updated_at).find_each do |item|
|
24
|
+
issues << "#{item.class} id #{item.id}: #{item.errors.messages}" if item.invalid?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
return 'ok' if issues.blank?
|
28
|
+
|
29
|
+
if email_report.present?
|
30
|
+
mail(to: email_report,
|
31
|
+
subject: 'DB Issues Discovered')
|
32
|
+
end
|
33
|
+
puts issues
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: valid_items
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vinny Glennon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '12.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '12.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.50.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.50.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: actionmailer
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.1'
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '6.0'
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '4.1'
|
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'
|
78
|
+
- - "<"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '6.0'
|
81
|
+
description: Goes through all your Rails ActiveRecord objects and check if they are
|
82
|
+
all still pass your model validations. You may have added new validations to your
|
83
|
+
model since creating your object, or ran update_column in your console to solve
|
84
|
+
a production issue. Find issues in your db before others do. Inspired by a RailsConf
|
85
|
+
talk by Ryan Laughlin and his talk at http://www.rofreg.com/talks/railsconf2018
|
86
|
+
email: vinnyglennon@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- lib/valid_items.rb
|
92
|
+
- test/test_valid_items.rb
|
93
|
+
homepage: http://rubygems.org/gems/valid_items
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '1.9'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.7.6
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Check that all your Rails ActiveRecord Objects still pass their model validations
|
117
|
+
test_files:
|
118
|
+
- test/test_valid_items.rb
|