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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c01429b95d15c52ae6c48436b02e036f7e28236d5a98cabd26549ad21fbb8757
4
- data.tar.gz: 1dee6a138c3d8a268bc5bd49e201975932e0054e20b36c4670e5abdb2971d8d5
3
+ metadata.gz: 8aa2a1ac69ee4d57ea5cb34f7c6ebe0a22a7958ab92bef61a4a643705734a780
4
+ data.tar.gz: e2a2120fc1916a24d98534a98bc6a5d5f6761eabc03c0a70e0e49d45334f33e1
5
5
  SHA512:
6
- metadata.gz: 6cf0b7a679244a478f3da47b51611fafbd47a627da23b9605f0cf4e3eb4e3b6b4dd8cdc0f203f7d531df56a4f1cbe4b247746f34b553232e3de51bf02ad1d0b1
7
- data.tar.gz: 9aac0880d5c8a377c94521b466602ce58f638e87315d1f4cccc487dc59d0e86e01525bed03b69b26fcc0f981adb98cd8f99d1a5b86d5421befeafe919b45246a
6
+ metadata.gz: 65384c2f8d4c0b76b73505cca1a674f85ed586eb07b685563144c70c263ea4836c546f9fc293f576b6024d5dec6030d372527be884008380ec578393436bfb86
7
+ data.tar.gz: '029e28fa3733eadfd67453b52ab6966b93753c3dce5e70b1ca2880b94a0b20a2575e3153f0f27d981c16a4119288dca1c4192f0598d409af00de45dd461982f3'
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- model_validator (1.2.2)
5
- rails (>= 4.0)
4
+ model_validator (1.3.0)
5
+ rails (>= 5.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -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
- ActiveRecord::Base.descendants
15
- .reject(&:abstract_class)
16
- .select { |type| type.subclasses.empty? }
17
- .reject { |type| @skip_models.include? type }
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ModelValidator
4
- VERSION = "1.2.2"
4
+ VERSION = "1.3.0"
5
5
  end
@@ -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", ">= 4.0"
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.2.2
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: '4.0'
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: '4.0'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: coveralls
29
29
  requirement: !ruby/object:Gem::Requirement