active_storage_validations 0.2 → 0.3
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.
- checksums.yaml +5 -5
- data/README.md +20 -0
- data/lib/active_storage_validations.rb +6 -1
- data/lib/active_storage_validations/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bf531e574b50d7706bdf19e76d59a43fe0ed24c24544949a5536b405f1f90366
|
4
|
+
data.tar.gz: e337c696052227779453d2e111a608f58e5ab26dca6d8f0ced9669b9c029272e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6489c3442ea44b4e804f0e8c3a11cb44a2d1aa5182b4390b1c533b8cc1288df8bb2c094d523bbbe0366f7ce8100abc0038c5ec82f1d698e414497e88662e82e
|
7
|
+
data.tar.gz: aa771cae35376ee2924a36b388927748c6e6de00b47a60aff1dc79e29cf1978a227ff31e0b9fe6e7f7a4a21338e2aea604bd6eb7e1f77ece085daafcec32a698
|
data/README.md
CHANGED
@@ -20,6 +20,20 @@ class User < ApplicationRecord
|
|
20
20
|
end
|
21
21
|
```
|
22
22
|
|
23
|
+
or
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class Project < ApplicationRecord
|
27
|
+
has_one_attached :preview
|
28
|
+
has_one_attached :attachment
|
29
|
+
|
30
|
+
validates :title, presence: true
|
31
|
+
|
32
|
+
validates :preview, attached: true
|
33
|
+
validates :attachment, attached: true, content_type: { in: 'application/pdf', message: 'is not a PDF' }
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
23
37
|
## Installation
|
24
38
|
|
25
39
|
Add this line to your application's Gemfile:
|
@@ -33,6 +47,12 @@ And then execute:
|
|
33
47
|
$ bundle
|
34
48
|
```
|
35
49
|
|
50
|
+
## Todo
|
51
|
+
* verify with remote storages
|
52
|
+
* better error message when content_type is invalid
|
53
|
+
* travis CI
|
54
|
+
* validation for file size
|
55
|
+
|
36
56
|
## Tests & Contributing
|
37
57
|
|
38
58
|
To run tests in root folder of gem `rake test`.
|
@@ -11,6 +11,11 @@ module ActiveStorageValidations
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class ContentTypeValidator < ActiveModel::EachValidator
|
14
|
+
|
15
|
+
# def initialize(options)
|
16
|
+
# super(options)
|
17
|
+
# end
|
18
|
+
|
14
19
|
def validate_each(record, attribute, value)
|
15
20
|
files = record.send(attribute)
|
16
21
|
|
@@ -24,7 +29,7 @@ module ActiveStorageValidations
|
|
24
29
|
|
25
30
|
files.each do |file|
|
26
31
|
unless content_type_valid?(file)
|
27
|
-
record.errors.add(attribute, :invalid)
|
32
|
+
record.errors.add(attribute, options[:message].presence || :invalid)
|
28
33
|
return
|
29
34
|
end
|
30
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_storage_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Kasyanchuk
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
version: '0'
|
87
87
|
requirements: []
|
88
88
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.6
|
89
|
+
rubygems_version: 2.7.6
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
92
|
summary: Validations for Active Storage
|