active_storage_validations 2.0.3 → 3.0.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 (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +122 -16
  3. data/config/locales/da.yml +9 -0
  4. data/config/locales/de.yml +9 -0
  5. data/config/locales/en-GB.yml +9 -0
  6. data/config/locales/en.yml +9 -0
  7. data/config/locales/es.yml +9 -0
  8. data/config/locales/fr.yml +9 -0
  9. data/config/locales/it.yml +9 -0
  10. data/config/locales/ja.yml +9 -0
  11. data/config/locales/nl.yml +9 -0
  12. data/config/locales/pl.yml +9 -0
  13. data/config/locales/pt-BR.yml +9 -0
  14. data/config/locales/ru.yml +9 -0
  15. data/config/locales/sv.yml +10 -1
  16. data/config/locales/tr.yml +9 -0
  17. data/config/locales/uk.yml +9 -0
  18. data/config/locales/vi.yml +9 -0
  19. data/config/locales/zh-CN.yml +9 -0
  20. data/lib/active_storage_validations/analyzer/pdf_analyzer.rb +89 -0
  21. data/lib/active_storage_validations/base_comparison_validator.rb +13 -1
  22. data/lib/active_storage_validations/duration_validator.rb +1 -0
  23. data/lib/active_storage_validations/matchers/base_comparison_validator_matcher.rb +11 -1
  24. data/lib/active_storage_validations/matchers/pages_validator_matcher.rb +39 -0
  25. data/lib/active_storage_validations/matchers.rb +1 -0
  26. data/lib/active_storage_validations/pages_validator.rb +61 -0
  27. data/lib/active_storage_validations/railtie.rb +6 -3
  28. data/lib/active_storage_validations/shared/asv_analyzable.rb +6 -0
  29. data/lib/active_storage_validations/shared/asv_attachable.rb +1 -1
  30. data/lib/active_storage_validations/shared/asv_errorable.rb +25 -1
  31. data/lib/active_storage_validations/size_validator.rb +1 -0
  32. data/lib/active_storage_validations/total_size_validator.rb +1 -0
  33. data/lib/active_storage_validations/version.rb +1 -1
  34. data/lib/active_storage_validations.rb +2 -0
  35. metadata +8 -2
@@ -20,9 +20,18 @@ module ActiveStorageValidations
20
20
  def add_error(record, attribute, error_type, **errors_options)
21
21
  return if record.errors.added?(attribute, error_type)
22
22
 
23
+ error = record.errors.add(attribute, error_type, **errors_options)
24
+
25
+ # Rails 8.0.2 introduced a new way to mark errors as nested
26
+ # https://github.com/igorkasyanchuk/active_storage_validations/issues/377
27
+ if Rails.gem_version >= Gem::Version.new("8.0.2")
28
+ # Mark errors as nested when they occur in a parent/child context
29
+ set_nested_error(record, error) if updating_through_parent?(record)
30
+ end
31
+
23
32
  # You can read https://api.rubyonrails.org/classes/ActiveModel/Errors.html#method-i-add
24
33
  # to better understand how Rails model errors work
25
- record.errors.add(attribute, error_type, **errors_options)
34
+ error
26
35
  end
27
36
 
28
37
  private
@@ -36,5 +45,20 @@ module ActiveStorageValidations
36
45
  when Hash then file[:filename]
37
46
  end.to_s
38
47
  end
48
+
49
+ def updating_through_parent?(record)
50
+ record.instance_variable_defined?(:@marked_for_destruction) ||
51
+ record.instance_variable_defined?(:@_destroy) ||
52
+ (record.respond_to?(:parent) && record.parent.present?)
53
+ end
54
+
55
+ def set_nested_error(record, error)
56
+ reflection = record.class.reflect_on_association(:parent)
57
+
58
+ if reflection
59
+ association = record.association(reflection.name)
60
+ record.errors.objects.append(ActiveRecord::Associations::NestedError.new(association, error))
61
+ end
62
+ end
39
63
  end
40
64
  end
@@ -10,6 +10,7 @@ module ActiveStorageValidations
10
10
  file_size_not_greater_than
11
11
  file_size_not_greater_than_or_equal_to
12
12
  file_size_not_between
13
+ file_size_not_equal_to
13
14
  ].freeze
14
15
 
15
16
  delegate :number_to_human_size, to: ActiveSupport::NumberHelper
@@ -10,6 +10,7 @@ module ActiveStorageValidations
10
10
  total_file_size_not_greater_than
11
11
  total_file_size_not_greater_than_or_equal_to
12
12
  total_file_size_not_between
13
+ total_file_size_not_equal_to
13
14
  ].freeze
14
15
 
15
16
  delegate :number_to_human_size, to: ActiveSupport::NumberHelper
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveStorageValidations
4
- VERSION = "2.0.3"
4
+ VERSION = "3.0.0"
5
5
  end
@@ -10,6 +10,7 @@ require "active_storage_validations/analyzer/image_analyzer/vips"
10
10
  require "active_storage_validations/analyzer/null_analyzer"
11
11
  require "active_storage_validations/analyzer/video_analyzer"
12
12
  require "active_storage_validations/analyzer/audio_analyzer"
13
+ require "active_storage_validations/analyzer/pdf_analyzer"
13
14
 
14
15
  require "active_storage_validations/extensors/asv_blob_metadatable"
15
16
  require "active_storage_validations/extensors/asv_marcelable"
@@ -23,6 +24,7 @@ require "active_storage_validations/aspect_ratio_validator"
23
24
  require "active_storage_validations/processable_file_validator"
24
25
  require "active_storage_validations/size_validator"
25
26
  require "active_storage_validations/total_size_validator"
27
+ require "active_storage_validations/pages_validator"
26
28
 
27
29
  require "active_storage_validations/engine"
28
30
  require "active_storage_validations/railtie"
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: 2.0.3
4
+ version: 3.0.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: 2025-04-19 00:00:00.000000000 Z
11
+ date: 2025-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -267,6 +267,7 @@ files:
267
267
  - lib/active_storage_validations/analyzer/image_analyzer/image_magick.rb
268
268
  - lib/active_storage_validations/analyzer/image_analyzer/vips.rb
269
269
  - lib/active_storage_validations/analyzer/null_analyzer.rb
270
+ - lib/active_storage_validations/analyzer/pdf_analyzer.rb
270
271
  - lib/active_storage_validations/analyzer/shared/asv_ff_probable.rb
271
272
  - lib/active_storage_validations/analyzer/video_analyzer.rb
272
273
  - lib/active_storage_validations/aspect_ratio_validator.rb
@@ -287,6 +288,7 @@ files:
287
288
  - lib/active_storage_validations/matchers/dimension_validator_matcher.rb
288
289
  - lib/active_storage_validations/matchers/duration_validator_matcher.rb
289
290
  - lib/active_storage_validations/matchers/limit_validator_matcher.rb
291
+ - lib/active_storage_validations/matchers/pages_validator_matcher.rb
290
292
  - lib/active_storage_validations/matchers/processable_file_validator_matcher.rb
291
293
  - lib/active_storage_validations/matchers/shared/asv_active_storageable.rb
292
294
  - lib/active_storage_validations/matchers/shared/asv_allow_blankable.rb
@@ -297,6 +299,7 @@ files:
297
299
  - lib/active_storage_validations/matchers/shared/asv_validatable.rb
298
300
  - lib/active_storage_validations/matchers/size_validator_matcher.rb
299
301
  - lib/active_storage_validations/matchers/total_size_validator_matcher.rb
302
+ - lib/active_storage_validations/pages_validator.rb
300
303
  - lib/active_storage_validations/processable_file_validator.rb
301
304
  - lib/active_storage_validations/railtie.rb
302
305
  - lib/active_storage_validations/shared/asv_active_storageable.rb
@@ -315,6 +318,9 @@ licenses:
315
318
  - MIT
316
319
  metadata:
317
320
  rubygems_mfa_required: 'true'
321
+ changelog_uri: https://github.com/igorkasyanchuk/active_storage_validations/blob/master/CHANGES.md
322
+ source_code_uri: https://github.com/igorkasyanchuk/active_storage_validations
323
+ bug_tracker_uri: https://github.com/igorkasyanchuk/active_storage_validations/issues
318
324
  post_install_message:
319
325
  rdoc_options: []
320
326
  require_paths: