active_record_auto_validations 0.0.3 → 0.0.4

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: d82df8dff2fe3dd3b03523499df936304e262721ea812792749059393602b662
4
- data.tar.gz: 2f34c86ef85893c79c215c8227458ab42e0503c46cca848527ddef8f71dc1642
3
+ metadata.gz: fed3fd2ca11387161a5229a84c3a2830e75ecfccccb690f7e3df623d1b7860b0
4
+ data.tar.gz: cbce1703024f0281fd689a87f135b5ee3c197d4fa282ff8937790748e160823c
5
5
  SHA512:
6
- metadata.gz: a3cee5f5a370c5c800efc0976eea8a350bb08d75bb9eab11d6fab4446d7ca2eab18096777daeff71f790bf51dd228c2a6c12e1d961c4eeda03541f1055f2be11
7
- data.tar.gz: f2eb99db19909b63de9de904a86f0dc9b119117c6391b27d5595e8b0ca0ad5c4013b3bfa164a2314dafe393e315ca148db60206f2a99fb79d593da69c382608f
6
+ metadata.gz: 6f3f3022a614e737fd610d50ece642e8d8b5db811cb5e5a4a8c228935e3103b266480a16ad71f0ecce1591ef6614c1d7b258cfdc6af9a22720e7c1c1e238c5e4
7
+ data.tar.gz: 95f0eaf31a5ae94683bd686c0677ac783f02a6c36ef816a20fdfbe74c7c6a2ce673366d4fbed1df40c13aa7bd48dd2b494977085bc0079a6cf010f7c46d1d362
@@ -1,11 +1,12 @@
1
1
  class ActiveRecordAutoValidations::AutoValidateModelClass
2
- attr_reader :model_class
2
+ attr_reader :ignore_column_names, :model_class
3
3
 
4
- def self.execute!(model_class:)
5
- ActiveRecordAutoValidations::AutoValidateModelClass.new(model_class: model_class).perform
4
+ def self.execute!(...)
5
+ ActiveRecordAutoValidations::AutoValidateModelClass.new(...).perform
6
6
  end
7
7
 
8
- def initialize(model_class:)
8
+ def initialize(model_class:, ignore_column_names: [])
9
+ @ignore_column_names = ignore_column_names
9
10
  @model_class = model_class
10
11
  end
11
12
 
@@ -18,7 +19,7 @@ class ActiveRecordAutoValidations::AutoValidateModelClass
18
19
  indexes
19
20
  rescue ActiveRecord::StatementInvalid => e
20
21
  # Database is probably not running - we need to ignore this to make stuff like db:migrate, db:schema:load work
21
- Rails.logger.error { "AutoValidate: Ignoring error while loading columns, because database might not be initialized: #{e.message}" }
22
+ Rails.logger.info { "AutoValidate: Ignoring error while loading columns, because database might not be initialized: #{e.message}" }
22
23
  return
23
24
  end
24
25
 
@@ -40,13 +41,25 @@ class ActiveRecordAutoValidations::AutoValidateModelClass
40
41
  @columns ||= model_class.columns
41
42
  end
42
43
 
44
+ def ignore_column?(column_name)
45
+ return true if column_name == "id" || column_name == "created_at" || column_name == "updated_at"
46
+
47
+ ignore_column_names.include?(column_name)
48
+ end
49
+
50
+ def ignore_index?(index)
51
+ return true unless index.unique
52
+
53
+ index.columns.any? { |index_column_name| ignore_column?(index_column_name) }
54
+ end
55
+
43
56
  def indexes
44
57
  @indexes ||= model_class.connection.indexes(model_class.table_name)
45
58
  end
46
59
 
47
60
  def insert_active_record_auto_validations_from_columns!
48
61
  columns.each do |column|
49
- next if column.name == "id" || column.name == "created_at" || column.name == "updated_at"
62
+ next if ignore_column?(column.name)
50
63
 
51
64
  auto_validate_pesence_on_column!(column) if auto_validate_presence_on_column?(column)
52
65
  auto_validate_max_length_on_column!(column) if auto_validate_max_length_on_column?(column)
@@ -55,11 +68,14 @@ class ActiveRecordAutoValidations::AutoValidateModelClass
55
68
 
56
69
  def insert_active_record_auto_validations_from_indexes!
57
70
  indexes.each do |index|
58
- next unless index.unique
71
+ next if ignore_index?(index)
59
72
 
60
73
  # Dont add uniqueness validation to ActsAsList position columns
61
74
  if index.columns.include?("position") && model_class.respond_to?(:acts_as_list_top)
62
- Rails.logger.info { "AutoValidate: Skipping unique validation on #{model_class.table_name}##{index.columns.join(",")} because it looks like ActsAsList" }
75
+ Rails.logger.info do
76
+ "AutoValidate: Skipping unique validation on #{model_class.table_name}##{index.columns.join(",")} because it looks like ActsAsList"
77
+ end
78
+
63
79
  next
64
80
  end
65
81
 
@@ -76,7 +92,7 @@ class ActiveRecordAutoValidations::AutoValidateModelClass
76
92
  end
77
93
 
78
94
  def auto_validate_presence_on_column?(column)
79
- !column.null && !column.name.end_with?("_id") && column.default.nil? && !presence_validation_exists_on_column?(column)
95
+ !column.null && !column.name.end_with?("_id") && column.default.nil? && column.default_function.nil? && !presence_validation_exists_on_column?(column)
80
96
  end
81
97
 
82
98
  def auto_validate_pesence_on_column!(column)
@@ -1,5 +1,5 @@
1
1
  module ActiveRecordAutoValidations; end
2
2
 
3
- class ActiveRecordAutoValidations::Engine < ::Rails::Engine
3
+ class ActiveRecordAutoValidations::Engine < Rails::Engine
4
4
  isolate_namespace ActiveRecordAutoValidations
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordAutoValidations
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.0.4".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_auto_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-28 00:00:00.000000000 Z
11
+ date: 2024-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,104 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 7.0.3
27
- - !ruby/object:Gem::Dependency
28
- name: dotenv-rails
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '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'
41
- - !ruby/object:Gem::Dependency
42
- name: mysql2
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec-rails
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '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'
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop-performance
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop-rails
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: rubocop-rspec
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
27
  description: Scans ActiveRecord models and adds automatic validations based on null,
126
28
  max length etc.
127
29
  email:
@@ -150,7 +52,7 @@ metadata:
150
52
  source_code_uri: https://github.com/kaspernj/active_record_auto_validations
151
53
  changelog_uri: https://github.com/kaspernj/active_record_auto_validations
152
54
  rubygems_mfa_required: 'true'
153
- post_install_message:
55
+ post_install_message:
154
56
  rdoc_options: []
155
57
  require_paths:
156
58
  - lib
@@ -165,8 +67,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
67
  - !ruby/object:Gem::Version
166
68
  version: '0'
167
69
  requirements: []
168
- rubygems_version: 3.3.7
169
- signing_key:
70
+ rubygems_version: 3.4.10
71
+ signing_key:
170
72
  specification_version: 4
171
73
  summary: Scans ActiveRecord models and adds automatic validations based on null, max
172
74
  length etc.