model_validator 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/model_validator/validator.rb +19 -4
- data/lib/model_validator/version.rb +1 -1
- data/model_validator.gemspec +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: 8aa2a1ac69ee4d57ea5cb34f7c6ebe0a22a7958ab92bef61a4a643705734a780
|
4
|
+
data.tar.gz: e2a2120fc1916a24d98534a98bc6a5d5f6761eabc03c0a70e0e49d45334f33e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65384c2f8d4c0b76b73505cca1a674f85ed586eb07b685563144c70c263ea4836c546f9fc293f576b6024d5dec6030d372527be884008380ec578393436bfb86
|
7
|
+
data.tar.gz: '029e28fa3733eadfd67453b52ab6966b93753c3dce5e70b1ca2880b94a0b20a2575e3153f0f27d981c16a4119288dca1c4192f0598d409af00de45dd461982f3'
|
data/Gemfile.lock
CHANGED
@@ -3,6 +3,18 @@
|
|
3
3
|
require "rails"
|
4
4
|
|
5
5
|
module ModelValidator
|
6
|
+
# ApplicationRecord is the base class used to loop up for all models to validate.
|
7
|
+
# So this class is mandatory for ModelValidator to work well.
|
8
|
+
class ApplicationRecordNotFound < StandardError
|
9
|
+
def message
|
10
|
+
<<~MSG
|
11
|
+
ApplicationRecord not found.
|
12
|
+
model_validator requires that all models extends a super class ApplicationRecord.
|
13
|
+
This is expected in a rails application since rails 5.0.
|
14
|
+
MSG
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
6
18
|
# Validation engine, which fetch, and validate each database records
|
7
19
|
class Validator
|
8
20
|
def initialize(handlers: [], skip_models: [])
|
@@ -11,10 +23,13 @@ module ModelValidator
|
|
11
23
|
end
|
12
24
|
|
13
25
|
def classes_to_validate
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
26
|
+
raise ApplicationRecordNotFound unless defined?(ApplicationRecord)
|
27
|
+
|
28
|
+
Rails.application.try(:eager_load!) if Rails.env.development?
|
29
|
+
ApplicationRecord.descendants
|
30
|
+
.reject(&:abstract_class)
|
31
|
+
.select { |type| type.subclasses.empty? }
|
32
|
+
.reject { |type| @skip_models.include? type }
|
18
33
|
end
|
19
34
|
|
20
35
|
def run
|
data/model_validator.gemspec
CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
|
30
30
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
-
spec.add_runtime_dependency "rails", ">=
|
33
|
+
spec.add_runtime_dependency "rails", ">= 5.0"
|
34
34
|
|
35
35
|
spec.add_development_dependency "coveralls"
|
36
36
|
spec.add_development_dependency "factory_bot"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: model_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jibidus
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: coveralls
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|