active_storage_validations 0.9.5 → 0.9.6

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: efa69aeeea1b171286c6ca464e38146dedef79d22853c35ec6ea0ce0ca089812
4
- data.tar.gz: e186561942afb6b295839565323d0bbed704de9e413b79ecc1fb194ada643ca5
3
+ metadata.gz: 52bbd6249bbadd7549ccd7daf17673e98ccfd757b15ec954b67c5d7ce3395c84
4
+ data.tar.gz: cf3664efb821cd7fe60b0536e0d394f900af6fb128161ab13d62d373b2018013
5
5
  SHA512:
6
- metadata.gz: c31ec657e1121427f19d7617d5efbeab639c6ebd87c0333c36510064e7b4d8125ffd8e4f5afa86121e626dd608d2ad1b859a3515c8bc7683e0793291a30c7fd2
7
- data.tar.gz: 3141abc08b6b33d90f9874a74e93f6aaddb0ebbd52bdd36ee292a1e0ff7d37cf65a8ced082d316f48cc8e0132320c4f83304d9823971906526096264129c0145
6
+ metadata.gz: bece2608d56156a83e468ffaf4ed31dead1769882457c1ff8480586ce0335122b475084f24f914d4d8083c5b4f2b891bda7465b25b2d34272ba76631c313167f
7
+ data.tar.gz: 56a1cbb1bd5bddc4cce887405eecd6d5e27cc9bfcdca97e636ccf43cf98ce29d9077e1b3e7a602dcb229cd24d25125024c4d83beba6f82050edc773b32d21ca4
data/README.md CHANGED
@@ -58,14 +58,15 @@ end
58
58
 
59
59
  ### More examples
60
60
 
61
- - Content type validation using symbols. In order to infer the correct mime type from the symbol, the types must be registered with `MimeMagic::EXTENSIONS`.
61
+ - Content type validation using symbols. In order to infer the correct mime type from the symbol, the types must be registered with `Marcel::EXTENSIONS` (`MimeMagic::EXTENSIONS` for Rails <= 6.1.3).
62
62
 
63
63
  ```ruby
64
64
  class User < ApplicationRecord
65
65
  has_one_attached :avatar
66
66
  has_many_attached :photos
67
67
 
68
- validates :avatar, attached: true, content_type: :png # MimeMagic.by_extension(:png).to_s => 'image/png'
68
+ validates :avatar, attached: true, content_type: :png # Marcel::Magic.by_extension(:png).to_s => 'image/png'
69
+ # Rails <= 6.1.3; MimeMagic.by_extension(:png).to_s => 'image/png'
69
70
  # or
70
71
  validates :photos, attached: true, content_type: [:png, :jpg, :jpeg]
71
72
  # or
@@ -292,6 +293,20 @@ To run tests in root folder of gem:
292
293
  * `BUNDLE_GEMFILE=gemfiles/rails_5_2.gemfile bundle exec rake test` to run for Rails 5.2
293
294
  * `BUNDLE_GEMFILE=gemfiles/rails_6_0.gemfile bundle exec rake test` to run for Rails 6.0
294
295
  * `BUNDLE_GEMFILE=gemfiles/rails_6_1.gemfile bundle exec rake test` to run for Rails 6.1
296
+ * `BUNDLE_GEMFILE=gemfiles/rails_next.gemfile bundle exec rake test` to run for Rails main branch
297
+
298
+ Snippet to run in console:
299
+
300
+ ```
301
+ BUNDLE_GEMFILE=gemfiles/rails_5_2.gemfile bundle
302
+ BUNDLE_GEMFILE=gemfiles/rails_6_0.gemfile bundle
303
+ BUNDLE_GEMFILE=gemfiles/rails_6_1.gemfile bundle
304
+ BUNDLE_GEMFILE=gemfiles/rails_next.gemfile bundle
305
+ BUNDLE_GEMFILE=gemfiles/rails_5_2.gemfile bundle exec rake test
306
+ BUNDLE_GEMFILE=gemfiles/rails_6_0.gemfile bundle exec rake test
307
+ BUNDLE_GEMFILE=gemfiles/rails_6_1.gemfile bundle exec rake test
308
+ BUNDLE_GEMFILE=gemfiles/rails_next.gemfile bundle exec rake test
309
+ ```
295
310
 
296
311
  ## Known issues
297
312
 
@@ -344,7 +359,9 @@ You are welcome to contribute.
344
359
  - https://github.com/jayshepherd
345
360
  - https://github.com/ohbarye
346
361
  - https://github.com/randsina
347
- - https://github.com/...
362
+ - https://github.com/vietqhoang
363
+ - https://github.com/kemenaran
364
+ - https://github.com/jrmhaig
348
365
 
349
366
  ## License
350
367
 
@@ -18,7 +18,7 @@ module ActiveStorageValidations
18
18
  raise ArgumentError, 'You must pass "aspect_ratio: :OPTION" option to the validator'
19
19
  end
20
20
 
21
- if Rails::VERSION::MAJOR >= 6
21
+ if Rails.gem_version >= Gem::Version.new('6.0.0')
22
22
  def validate_each(record, attribute, _value)
23
23
  return true unless record.send(attribute).attached?
24
24
 
@@ -34,7 +34,7 @@ module ActiveStorageValidations
34
34
  end
35
35
 
36
36
 
37
- if Rails::VERSION::MAJOR >= 6
37
+ if Rails.gem_version >= Gem::Version.new('6.0.0')
38
38
  def validate_each(record, attribute, _value)
39
39
  return true unless record.send(attribute).attached?
40
40
 
@@ -22,7 +22,7 @@ module ActiveStorageValidations
22
22
  end
23
23
 
24
24
  def self.mock_metadata(attachment, width, height)
25
- if Rails::VERSION::MAJOR >= 6
25
+ if Rails.gem_version >= Gem::Version.new('6.0.0')
26
26
  # Mock the Metadata class for rails 6
27
27
  mock = OpenStruct.new(metadata: { width: width, height: height })
28
28
  stub_method(ActiveStorageValidations::Metadata, :new, mock) do
@@ -21,17 +21,16 @@ module ActiveStorageValidations
21
21
  def read_image
22
22
  is_string = file.is_a?(String)
23
23
  if is_string || file.is_a?(ActiveStorage::Blob)
24
- if is_string
25
- # If Rails 5.2 or 6.0, use `find_signed`
26
- if Rails::VERSION::MAJOR < 6 || (Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR == 0)
27
- blob = ActiveStorage::Blob.find_signed(file)
28
- # If Rails 6.1 or higher, use `find_signed!`
29
- elsif Rails::VERSION::MAJOR > 6 || (Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR >= 1)
30
- blob = ActiveStorage::Blob.find_signed!(file)
24
+ blob =
25
+ if is_string
26
+ if Rails.gem_version < Gem::Version.new('6.1.0')
27
+ ActiveStorage::Blob.find_signed(file)
28
+ else
29
+ ActiveStorage::Blob.find_signed!(file)
30
+ end
31
+ else
32
+ file
31
33
  end
32
- else
33
- blob = file
34
- end
35
34
 
36
35
  tempfile = Tempfile.new(["ActiveStorage-#{blob.id}-", blob.filename.extension_with_delimiter])
37
36
  tempfile.binmode
@@ -25,6 +25,9 @@ module ActiveStorageValidations
25
25
  next if content_size_valid?(file.blob.byte_size)
26
26
 
27
27
  errors_options[:file_size] = number_to_human_size(file.blob.byte_size)
28
+ errors_options[:min_size] = number_to_human_size(min_size)
29
+ errors_options[:max_size] = number_to_human_size(max_size)
30
+
28
31
  record.errors.add(attribute, :file_size_out_of_range, **errors_options)
29
32
  break
30
33
  end
@@ -43,5 +46,13 @@ module ActiveStorageValidations
43
46
  file_size >= options[:greater_than_or_equal_to]
44
47
  end
45
48
  end
49
+
50
+ def min_size
51
+ options[:between]&.min || options[:greater_than] || options[:greater_than_or_equal_to]
52
+ end
53
+
54
+ def max_size
55
+ options[:between]&.max || options[:less_than] || options[:less_than_or_equal_to]
56
+ end
46
57
  end
47
58
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveStorageValidations
4
- VERSION = '0.9.5'
4
+ VERSION = '0.9.6'
5
5
  end
metadata CHANGED
@@ -1,17 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_storage_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-26 00:00:00.000000000 Z
11
+ date: 2021-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: activejob
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 5.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 5.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: activestorage
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 5.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 5.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
15
57
  requirement: !ruby/object:Gem::Requirement
16
58
  requirements:
17
59
  - - ">="
@@ -153,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
195
  - !ruby/object:Gem::Version
154
196
  version: '0'
155
197
  requirements: []
156
- rubygems_version: 3.0.3
198
+ rubygems_version: 3.1.4
157
199
  signing_key:
158
200
  specification_version: 4
159
201
  summary: Validations for Active Storage