active_storage_validations 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +145 -73
  3. data/config/locales/da.yml +33 -0
  4. data/config/locales/de.yml +6 -0
  5. data/config/locales/en.yml +5 -0
  6. data/config/locales/es.yml +6 -0
  7. data/config/locales/fr.yml +6 -0
  8. data/config/locales/it.yml +6 -0
  9. data/config/locales/ja.yml +6 -0
  10. data/config/locales/nl.yml +6 -0
  11. data/config/locales/pl.yml +6 -0
  12. data/config/locales/pt-BR.yml +5 -0
  13. data/config/locales/ru.yml +7 -1
  14. data/config/locales/sv.yml +10 -1
  15. data/config/locales/tr.yml +6 -0
  16. data/config/locales/uk.yml +6 -0
  17. data/config/locales/vi.yml +6 -0
  18. data/config/locales/zh-CN.yml +6 -0
  19. data/lib/active_storage_validations/aspect_ratio_validator.rb +49 -22
  20. data/lib/active_storage_validations/attached_validator.rb +18 -4
  21. data/lib/active_storage_validations/base_size_validator.rb +66 -0
  22. data/lib/active_storage_validations/concerns/errorable.rb +38 -0
  23. data/lib/active_storage_validations/concerns/symbolizable.rb +12 -0
  24. data/lib/active_storage_validations/content_type_validator.rb +47 -8
  25. data/lib/active_storage_validations/dimension_validator.rb +30 -15
  26. data/lib/active_storage_validations/limit_validator.rb +48 -8
  27. data/lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb +119 -0
  28. data/lib/active_storage_validations/matchers/attached_validator_matcher.rb +46 -33
  29. data/lib/active_storage_validations/matchers/base_size_validator_matcher.rb +134 -0
  30. data/lib/active_storage_validations/matchers/concerns/active_storageable.rb +17 -0
  31. data/lib/active_storage_validations/matchers/concerns/allow_blankable.rb +26 -0
  32. data/lib/active_storage_validations/matchers/concerns/attachable.rb +48 -0
  33. data/lib/active_storage_validations/matchers/concerns/contextable.rb +47 -0
  34. data/lib/active_storage_validations/matchers/concerns/messageable.rb +26 -0
  35. data/lib/active_storage_validations/matchers/concerns/rspecable.rb +25 -0
  36. data/lib/active_storage_validations/matchers/concerns/validatable.rb +54 -0
  37. data/lib/active_storage_validations/matchers/content_type_validator_matcher.rb +76 -52
  38. data/lib/active_storage_validations/matchers/dimension_validator_matcher.rb +93 -55
  39. data/lib/active_storage_validations/matchers/processable_image_validator_matcher.rb +78 -0
  40. data/lib/active_storage_validations/matchers/size_validator_matcher.rb +9 -88
  41. data/lib/active_storage_validations/matchers/total_size_validator_matcher.rb +40 -0
  42. data/lib/active_storage_validations/matchers.rb +3 -0
  43. data/lib/active_storage_validations/metadata.rb +60 -28
  44. data/lib/active_storage_validations/processable_image_validator.rb +16 -5
  45. data/lib/active_storage_validations/size_validator.rb +18 -43
  46. data/lib/active_storage_validations/total_size_validator.rb +49 -0
  47. data/lib/active_storage_validations/version.rb +1 -1
  48. data/lib/active_storage_validations.rb +3 -2
  49. metadata +42 -26
  50. data/lib/active_storage_validations/error_handler.rb +0 -18
@@ -4,29 +4,18 @@ module ActiveStorageValidations
4
4
 
5
5
  attr_reader :file
6
6
 
7
+ DEFAULT_IMAGE_PROCESSOR = :mini_magick.freeze
8
+
7
9
  def initialize(file)
8
10
  require_image_processor
9
11
  @file = file
10
12
  end
11
13
 
12
- def image_processor
13
- Rails.application.config.active_storage.variant_processor
14
- end
15
-
16
- def exception_class
17
- if image_processor == :vips && defined?(Vips)
18
- Vips::Error
19
- elsif defined?(MiniMagick)
20
- MiniMagick::Error
21
- end
22
- end
23
-
24
- def require_image_processor
25
- if image_processor == :vips
26
- require 'vips' unless defined?(Vips)
27
- else
28
- require 'mini_magick' unless defined?(MiniMagick)
29
- end
14
+ def valid?
15
+ read_image
16
+ true
17
+ rescue InvalidImageError
18
+ false
30
19
  end
31
20
 
32
21
  def metadata
@@ -42,14 +31,31 @@ module ActiveStorageValidations
42
31
  {}
43
32
  end
44
33
 
45
- def valid?
46
- read_image
47
- true
48
- rescue InvalidImageError
49
- false
34
+ private
35
+
36
+ def image_processor
37
+ # Rails returns nil for default image processor, because it is set in an after initialize callback
38
+ # https://github.com/rails/rails/blob/89d8569abe2564c8187debf32dd3b4e33d6ad983/activestorage/lib/active_storage/engine.rb
39
+ Rails.application.config.active_storage.variant_processor || DEFAULT_IMAGE_PROCESSOR
50
40
  end
51
41
 
52
- private
42
+ def require_image_processor
43
+ case image_processor
44
+ when :vips then require 'vips' unless defined?(Vips)
45
+ when :mini_magick then require 'mini_magick' unless defined?(MiniMagick)
46
+ end
47
+ end
48
+
49
+ def exception_class
50
+ case image_processor
51
+ when :vips then Vips::Error
52
+ when :mini_magick then MiniMagick::Error
53
+ end
54
+ end
55
+
56
+ def vips_image_processor?
57
+ image_processor == :vips
58
+ end
53
59
 
54
60
  def read_image
55
61
  is_string = file.is_a?(String)
@@ -95,23 +101,49 @@ module ActiveStorageValidations
95
101
  end
96
102
 
97
103
  def new_image_from_path(path)
98
- if image_processor == :vips && defined?(Vips) && (Vips::get_suffixes.include?(File.extname(path).downcase) || !Vips::respond_to?(:vips_foreign_get_suffixes))
99
- Vips::Image.new_from_file(path)
104
+ if vips_image_processor? && (supported_vips_suffix?(path) || vips_version_below_8_8? || open_uri_tempfile?(path))
105
+ begin
106
+ Vips::Image.new_from_file(path)
107
+ rescue exception_class
108
+ # We handle cases where an error is raised when reading the file
109
+ # because Vips can throw errors rather than returning false
110
+ # We stumble upon this issue while reading 0 byte size file
111
+ # https://github.com/janko/image_processing/issues/97
112
+ false
113
+ end
100
114
  elsif defined?(MiniMagick)
101
115
  MiniMagick::Image.new(path)
102
116
  end
103
117
  end
104
118
 
119
+ def supported_vips_suffix?(path)
120
+ Vips::get_suffixes.include?(File.extname(path).downcase)
121
+ end
122
+
123
+ def vips_version_below_8_8?
124
+ # FYI, Vips 8.8 was released in 2019
125
+ # https://github.com/libvips/libvips/releases/tag/v8.8.0
126
+ !Vips::respond_to?(:vips_foreign_get_suffixes)
127
+ end
128
+
129
+ def open_uri_tempfile?(path)
130
+ # When trying to open urls for 'large' images, OpenURI will return a
131
+ # tempfile. That tempfile does not have an extension indicating the type
132
+ # of file. However, Vips will be able to process it anyway.
133
+ # The 'large' file value is derived from OpenUri::Buffer class (> 10ko)
134
+ path.split('/').last.starts_with?("open-uri")
135
+ end
136
+
105
137
  def valid_image?(image)
106
138
  return false unless image
107
139
 
108
- image_processor == :vips && image.is_a?(Vips::Image) ? image.avg : image.valid?
140
+ vips_image_processor? && image.is_a?(Vips::Image) ? image.avg : image.valid?
109
141
  rescue exception_class
110
142
  false
111
143
  end
112
144
 
113
145
  def rotated_image?(image)
114
- if image_processor == :vips && image.is_a?(Vips::Image)
146
+ if vips_image_processor? && image.is_a?(Vips::Image)
115
147
  image.get('exif-ifd0-Orientation').include?('Right-top') ||
116
148
  image.get('exif-ifd0-Orientation').include?('Left-bottom')
117
149
  else
@@ -1,25 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'concerns/errorable.rb'
4
+ require_relative 'concerns/symbolizable.rb'
3
5
  require_relative 'metadata.rb'
4
6
 
5
7
  module ActiveStorageValidations
6
8
  class ProcessableImageValidator < ActiveModel::EachValidator # :nodoc
7
9
  include OptionProcUnfolding
8
- include ErrorHandler
10
+ include Errorable
11
+ include Symbolizable
12
+
13
+ ERROR_TYPES = %i[
14
+ image_not_processable
15
+ ].freeze
9
16
 
10
17
  if Rails.gem_version >= Gem::Version.new('6.0.0')
11
18
  def validate_each(record, attribute, _value)
12
19
  return true unless record.send(attribute).attached?
13
20
 
14
- errors_options = initialize_error_options(options)
15
-
16
21
  changes = record.attachment_changes[attribute.to_s]
17
22
  return true if changes.blank?
18
23
 
19
24
  files = Array.wrap(changes.is_a?(ActiveStorage::Attached::Changes::CreateMany) ? changes.attachables : changes.attachable)
20
25
 
21
26
  files.each do |file|
22
- add_error(record, attribute, :image_not_processable, **errors_options) unless Metadata.new(file).valid?
27
+ if !Metadata.new(file).valid?
28
+ errors_options = initialize_error_options(options, file)
29
+ add_error(record, attribute, ERROR_TYPES.first , **errors_options) unless Metadata.new(file).valid?
30
+ end
23
31
  end
24
32
  end
25
33
  else
@@ -30,7 +38,10 @@ module ActiveStorageValidations
30
38
  files = Array.wrap(record.send(attribute))
31
39
 
32
40
  files.each do |file|
33
- add_error(record, attribute, :image_not_processable, **errors_options) unless Metadata.new(file).valid?
41
+ if !Metadata.new(file).valid?
42
+ errors_options = initialize_error_options(options, file)
43
+ add_error(record, attribute, ERROR_TYPES.first , **errors_options) unless Metadata.new(file).valid?
44
+ end
34
45
  end
35
46
  end
36
47
  end
@@ -1,63 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ActiveStorageValidations
4
- class SizeValidator < ActiveModel::EachValidator # :nodoc:
5
- include OptionProcUnfolding
6
- include ErrorHandler
7
-
8
- delegate :number_to_human_size, to: ActiveSupport::NumberHelper
3
+ require_relative 'concerns/errorable.rb'
4
+ require_relative 'concerns/symbolizable.rb'
5
+ require_relative 'base_size_validator.rb'
9
6
 
10
- AVAILABLE_CHECKS = %i[less_than less_than_or_equal_to greater_than greater_than_or_equal_to between].freeze
11
-
12
- def check_validity!
13
- unless AVAILABLE_CHECKS.one? { |argument| options.key?(argument) }
14
- raise ArgumentError, 'You must pass either :less_than(_or_equal_to), :greater_than(_or_equal_to), or :between to the validator'
15
- end
16
- end
7
+ module ActiveStorageValidations
8
+ class SizeValidator < BaseSizeValidator
9
+ ERROR_TYPES = %i[
10
+ file_size_not_less_than
11
+ file_size_not_less_than_or_equal_to
12
+ file_size_not_greater_than
13
+ file_size_not_greater_than_or_equal_to
14
+ file_size_not_between
15
+ ].freeze
17
16
 
18
17
  def validate_each(record, attribute, _value)
19
- # only attached
20
18
  return true unless record.send(attribute).attached?
21
19
 
22
20
  files = Array.wrap(record.send(attribute))
23
-
24
- errors_options = initialize_error_options(options)
25
-
26
21
  flat_options = unfold_procs(record, self.options, AVAILABLE_CHECKS)
27
22
 
28
23
  files.each do |file|
29
- next if content_size_valid?(file.blob.byte_size, flat_options)
24
+ next if is_valid?(file.blob.byte_size, flat_options)
30
25
 
26
+ errors_options = initialize_error_options(options, file)
27
+ populate_error_options(errors_options, flat_options)
31
28
  errors_options[:file_size] = number_to_human_size(file.blob.byte_size)
32
- errors_options[:min_size] = number_to_human_size(min_size(flat_options))
33
- errors_options[:max_size] = number_to_human_size(max_size(flat_options))
34
- error_type = "file_size_not_#{flat_options.keys.first}".to_sym
29
+
30
+ keys = AVAILABLE_CHECKS & flat_options.keys
31
+ error_type = "file_size_not_#{keys.first}".to_sym
35
32
 
36
33
  add_error(record, attribute, error_type, **errors_options)
37
34
  break
38
35
  end
39
36
  end
40
-
41
- def content_size_valid?(file_size, flat_options)
42
- if flat_options[:between].present?
43
- flat_options[:between].include?(file_size)
44
- elsif flat_options[:less_than].present?
45
- file_size < flat_options[:less_than]
46
- elsif flat_options[:less_than_or_equal_to].present?
47
- file_size <= flat_options[:less_than_or_equal_to]
48
- elsif flat_options[:greater_than].present?
49
- file_size > flat_options[:greater_than]
50
- elsif flat_options[:greater_than_or_equal_to].present?
51
- file_size >= flat_options[:greater_than_or_equal_to]
52
- end
53
- end
54
-
55
- def min_size(flat_options)
56
- flat_options[:between]&.min || flat_options[:greater_than] || flat_options[:greater_than_or_equal_to]
57
- end
58
-
59
- def max_size(flat_options)
60
- flat_options[:between]&.max || flat_options[:less_than] || flat_options[:less_than_or_equal_to]
61
- end
62
37
  end
63
38
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'concerns/errorable.rb'
4
+ require_relative 'concerns/symbolizable.rb'
5
+ require_relative 'base_size_validator.rb'
6
+
7
+ module ActiveStorageValidations
8
+ class TotalSizeValidator < BaseSizeValidator
9
+ ERROR_TYPES = %i[
10
+ total_file_size_not_less_than
11
+ total_file_size_not_less_than_or_equal_to
12
+ total_file_size_not_greater_than
13
+ total_file_size_not_greater_than_or_equal_to
14
+ total_file_size_not_between
15
+ ].freeze
16
+
17
+ def validate_each(record, attribute, _value)
18
+ custom_check_validity!(record, attribute)
19
+
20
+ return true unless record.send(attribute).attached?
21
+
22
+ files = Array.wrap(record.send(attribute))
23
+ flat_options = unfold_procs(record, self.options, AVAILABLE_CHECKS)
24
+
25
+ total_file_size = files.sum { |file| file.blob.byte_size }
26
+
27
+ return true if is_valid?(total_file_size, flat_options)
28
+
29
+ errors_options = initialize_error_options(options, nil)
30
+ populate_error_options(errors_options, flat_options)
31
+ errors_options[:total_file_size] = number_to_human_size(total_file_size)
32
+
33
+ keys = AVAILABLE_CHECKS & flat_options.keys
34
+ error_type = "total_file_size_not_#{keys.first}".to_sym
35
+
36
+ add_error(record, attribute, error_type, **errors_options)
37
+ end
38
+
39
+ private
40
+
41
+ def custom_check_validity!(record, attribute)
42
+ # We can't perform this check in the #check_validity! hook because we do not
43
+ # have enough data (only options & attributes are accessible)
44
+ unless record.send(attribute).is_a?(ActiveStorage::Attached::Many)
45
+ raise ArgumentError, 'This validator is only available for has_many_attached relations'
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveStorageValidations
4
- VERSION = '1.1.1'
4
+ VERSION = '1.2.0'
5
5
  end
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_model'
4
+ require 'active_support/concern'
4
5
 
5
6
  require 'active_storage_validations/railtie'
6
7
  require 'active_storage_validations/engine'
7
8
  require 'active_storage_validations/option_proc_unfolding'
8
- require 'active_storage_validations/error_handler'
9
9
  require 'active_storage_validations/attached_validator'
10
10
  require 'active_storage_validations/content_type_validator'
11
- require 'active_storage_validations/size_validator'
12
11
  require 'active_storage_validations/limit_validator'
13
12
  require 'active_storage_validations/dimension_validator'
14
13
  require 'active_storage_validations/aspect_ratio_validator'
15
14
  require 'active_storage_validations/processable_image_validator'
15
+ require 'active_storage_validations/size_validator'
16
+ require 'active_storage_validations/total_size_validator'
16
17
 
17
18
  ActiveSupport.on_load(:active_record) do
18
19
  send :include, ActiveStorageValidations
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_storage_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-26 00:00:00.000000000 Z
11
+ date: 2024-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -81,49 +81,49 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.3'
83
83
  - !ruby/object:Gem::Dependency
84
- name: mini_magick
84
+ name: marcel
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 4.9.5
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 4.9.5
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: ruby-vips
98
+ name: mini_magick
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: 2.1.0
103
+ version: 4.9.5
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: 2.1.0
110
+ version: 4.9.5
111
111
  - !ruby/object:Gem::Dependency
112
- name: pry
112
+ name: minitest-focus
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '1.4'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: '1.4'
125
125
  - !ruby/object:Gem::Dependency
126
- name: rubocop
126
+ name: pry
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -137,21 +137,21 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: sqlite3
140
+ name: ruby-vips
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
144
144
  - !ruby/object:Gem::Version
145
- version: '0'
145
+ version: 2.1.0
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
- version: '0'
152
+ version: 2.1.0
153
153
  - !ruby/object:Gem::Dependency
154
- name: marcel
154
+ name: simplecov
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
@@ -165,7 +165,7 @@ dependencies:
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
- name: simplecov
168
+ name: sqlite3
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - ">="
@@ -179,19 +179,19 @@ dependencies:
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
- name: globalid
182
+ name: webmock
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - ">="
186
186
  - !ruby/object:Gem::Version
187
- version: '0'
187
+ version: '3'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
- version: '0'
194
+ version: '3'
195
195
  description: Validations for Active Storage (presence)
196
196
  email:
197
197
  - igorkasyanchuk@gmail.com
@@ -202,6 +202,7 @@ files:
202
202
  - MIT-LICENSE
203
203
  - README.md
204
204
  - Rakefile
205
+ - config/locales/da.yml
205
206
  - config/locales/de.yml
206
207
  - config/locales/en.yml
207
208
  - config/locales/es.yml
@@ -220,27 +221,42 @@ files:
220
221
  - lib/active_storage_validations.rb
221
222
  - lib/active_storage_validations/aspect_ratio_validator.rb
222
223
  - lib/active_storage_validations/attached_validator.rb
224
+ - lib/active_storage_validations/base_size_validator.rb
225
+ - lib/active_storage_validations/concerns/errorable.rb
226
+ - lib/active_storage_validations/concerns/symbolizable.rb
223
227
  - lib/active_storage_validations/content_type_validator.rb
224
228
  - lib/active_storage_validations/dimension_validator.rb
225
229
  - lib/active_storage_validations/engine.rb
226
- - lib/active_storage_validations/error_handler.rb
227
230
  - lib/active_storage_validations/limit_validator.rb
228
231
  - lib/active_storage_validations/matchers.rb
232
+ - lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb
229
233
  - lib/active_storage_validations/matchers/attached_validator_matcher.rb
234
+ - lib/active_storage_validations/matchers/base_size_validator_matcher.rb
235
+ - lib/active_storage_validations/matchers/concerns/active_storageable.rb
236
+ - lib/active_storage_validations/matchers/concerns/allow_blankable.rb
237
+ - lib/active_storage_validations/matchers/concerns/attachable.rb
238
+ - lib/active_storage_validations/matchers/concerns/contextable.rb
239
+ - lib/active_storage_validations/matchers/concerns/messageable.rb
240
+ - lib/active_storage_validations/matchers/concerns/rspecable.rb
241
+ - lib/active_storage_validations/matchers/concerns/validatable.rb
230
242
  - lib/active_storage_validations/matchers/content_type_validator_matcher.rb
231
243
  - lib/active_storage_validations/matchers/dimension_validator_matcher.rb
244
+ - lib/active_storage_validations/matchers/processable_image_validator_matcher.rb
232
245
  - lib/active_storage_validations/matchers/size_validator_matcher.rb
246
+ - lib/active_storage_validations/matchers/total_size_validator_matcher.rb
233
247
  - lib/active_storage_validations/metadata.rb
234
248
  - lib/active_storage_validations/option_proc_unfolding.rb
235
249
  - lib/active_storage_validations/processable_image_validator.rb
236
250
  - lib/active_storage_validations/railtie.rb
237
251
  - lib/active_storage_validations/size_validator.rb
252
+ - lib/active_storage_validations/total_size_validator.rb
238
253
  - lib/active_storage_validations/version.rb
239
254
  - lib/tasks/active_storage_validations_tasks.rake
240
255
  homepage: https://github.com/igorkasyanchuk/active_storage_validations
241
256
  licenses:
242
257
  - MIT
243
- metadata: {}
258
+ metadata:
259
+ rubygems_mfa_required: 'true'
244
260
  post_install_message:
245
261
  rdoc_options: []
246
262
  require_paths:
@@ -249,14 +265,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
249
265
  requirements:
250
266
  - - ">="
251
267
  - !ruby/object:Gem::Version
252
- version: '0'
268
+ version: 2.5.0
253
269
  required_rubygems_version: !ruby/object:Gem::Requirement
254
270
  requirements:
255
271
  - - ">="
256
272
  - !ruby/object:Gem::Version
257
273
  version: '0'
258
274
  requirements: []
259
- rubygems_version: 3.4.10
275
+ rubygems_version: 3.5.11
260
276
  signing_key:
261
277
  specification_version: 4
262
278
  summary: Validations for Active Storage
@@ -1,18 +0,0 @@
1
- module ActiveStorageValidations
2
- module ErrorHandler
3
-
4
- def initialize_error_options(options)
5
- {
6
- message: (options[:message] if options[:message].present?)
7
- }
8
- end
9
-
10
- def add_error(record, attribute, default_message, **errors_options)
11
- message = errors_options[:message].presence || default_message
12
- return if record.errors.added?(attribute, message)
13
-
14
- record.errors.add(attribute, message, **errors_options)
15
- end
16
-
17
- end
18
- end