active_storage_validations 0.2 → 0.3

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
- SHA1:
3
- metadata.gz: 0cd3e51c1736b2926e53a3ca8ffbde43a42d23cc
4
- data.tar.gz: d84e8f896c60622cffd597d7480549b05eaa5b84
2
+ SHA256:
3
+ metadata.gz: bf531e574b50d7706bdf19e76d59a43fe0ed24c24544949a5536b405f1f90366
4
+ data.tar.gz: e337c696052227779453d2e111a608f58e5ab26dca6d8f0ced9669b9c029272e
5
5
  SHA512:
6
- metadata.gz: 038e132b37ea4248c54dd604dd5e5f57f1ae239a692105366ebe34e561eba220e1d95924418a83f807d3ba87b39f889f18facac92a64781c7fc6d0a3fed0fbd6
7
- data.tar.gz: 6a4af9ce49ff16d25bfe975a68f3c04faad4dd83636a59017ff8d9382657133a33e362a33ad7ed5bf9c9b89cb7ce2750c3121c30394adc7f1fce4a6f89be12b1
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
@@ -1,3 +1,3 @@
1
1
  module ActiveStorageValidations
2
- VERSION = '0.2'
2
+ VERSION = '0.3'
3
3
  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.2'
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.8
89
+ rubygems_version: 2.7.6
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Validations for Active Storage