active_storage_validations 0.8.0 → 0.8.1

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: 90da6d94caed4f46393b01b35be7b3d0015304c991c4a04919122ec0256a2692
4
- data.tar.gz: 3ea9462025ac280ac8201f46448c721e4d6633fcb13403c0fce75a5e89b841ad
3
+ metadata.gz: 3f4d056a6bc935d7d423adedecf19fc841ba2d4711315eb4586cc54f39f0cc7a
4
+ data.tar.gz: a2474738de0db8878368672a4fdf393a06ab18f3db87a9a3ff320c4e7a0536ed
5
5
  SHA512:
6
- metadata.gz: efdb486d80faeb8fd8a0d629f8c666cd34d7936d43d6b15a4806c169258f4c203fcd25618988af5e50c93a8b6020e64f4fabd30d6b16560cbda3e5553ce2699b
7
- data.tar.gz: 7b588e741bb0dbb44c0fa5c1506b37711d13eb605098ed4e04e27ec02450ab902c76364e9d72fb4b1a246c6ed641c611640c632ebbfb44835a82bc0e6e74a6ed
6
+ metadata.gz: 256142921c422090717ce89451700a9635a83ac69e52709ba07bf3a8acfa18a15a7e328a47e232e4aa0ff5237fabe7d0b5f73fe3a9e1bf13458fad665887cd9b
7
+ data.tar.gz: 550358993e4bfa899503821d3dcdbbf8c4daced1255f9daff4bbd2c603164f439228b230a4d3cd05155395325a838e2112dd7a956e9373bfb73e42219a5a761a
data/README.md CHANGED
@@ -32,7 +32,7 @@ class User < ApplicationRecord
32
32
  validates :photos, attached: true, content_type: ['image/png', 'image/jpg', 'image/jpeg'],
33
33
  dimension: { width: { min: 800, max: 2400 },
34
34
  height: { min: 600, max: 1800 }, message: 'is not given between dimension' }
35
- validates :image, attached: true,
35
+ validates :image, attached: true,
36
36
  content_type: ['image/png', 'image/jpg'],
37
37
  aspect_ratio: :landscape
38
38
  end
@@ -56,6 +56,18 @@ end
56
56
 
57
57
  ### More examples
58
58
 
59
+ - Content type validation using symbols. In order to infer the correct mime type from the symbol, the types must be registered with `Mime::Type`.
60
+
61
+ ```ruby
62
+ class User < ApplicationRecord
63
+ has_one_attached :avatar
64
+ has_many_attached :photos
65
+
66
+ validates :avatar, attached: true, content_type: :png # Mime[:png].to_s => 'image/png'
67
+ validates :photos, attached: true, content_type: [:png, :jpg, :jpeg]
68
+ end
69
+ ```
70
+
59
71
  - Dimension validation with `width`, `height` and `in`.
60
72
 
61
73
  ```ruby
@@ -68,7 +80,7 @@ class User < ApplicationRecord
68
80
  end
69
81
  ```
70
82
 
71
- - Dimension validation with `min` and `max` range for width and height.
83
+ - Dimension validation with `min` and `max` range for width and height:
72
84
 
73
85
  ```ruby
74
86
  class User < ApplicationRecord
@@ -84,6 +96,21 @@ class User < ApplicationRecord
84
96
  end
85
97
  ```
86
98
 
99
+ - Aspect ration validation:
100
+
101
+ ```ruby
102
+ class User < ApplicationRecord
103
+ has_one_attached :avatar
104
+ has_one_attached :photo
105
+ has_many_attached :photos
106
+
107
+ validates :avatar, aspect_ratio: :square
108
+ validates :photo, aspect_ratio: :landscape
109
+
110
+ # you can also pass dynamic aspect ratio, like :is_4_3, :is_16_9, etc
111
+ validates :photos, aspect_ratio: :is_4_3
112
+ end
113
+
87
114
  ## Internationalization (I18n)
88
115
 
89
116
  Active Storage Validations use I18n for errors messages. For this add there keys in your translation file:
@@ -197,6 +224,14 @@ You are welcome to contribute.
197
224
  - https://github.com/D-system
198
225
  - https://github.com/ivanelrey
199
226
  - https://github.com/phlegx
227
+ - https://github.com/rr-dev
228
+ - https://github.com/dsmalko
229
+ - https://github.com/danderozier
230
+ - https://github.com/cseelus
231
+ - https://github.com/vkinelev
232
+ - https://github.com/reed
233
+ - https://github.com/connorshea
234
+ - https://github.com/Atul9
200
235
 
201
236
  ## License
202
237
 
@@ -20,7 +20,9 @@ module ActiveStorageValidations
20
20
  end
21
21
 
22
22
  def types
23
- Array.wrap(options[:with]) + Array.wrap(options[:in])
23
+ (Array.wrap(options[:with]) + Array.wrap(options[:in])).map do |type|
24
+ Mime[type] || type
25
+ end
24
26
  end
25
27
 
26
28
  def types_to_human_format
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveStorageValidations
4
- VERSION = '0.8.0'
4
+ VERSION = '0.8.1'
5
5
  end
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: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-01 00:00:00.000000000 Z
11
+ date: 2019-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  requirements: []
140
- rubygems_version: 3.0.2
140
+ rubygems_version: 3.0.4
141
141
  signing_key:
142
142
  specification_version: 4
143
143
  summary: Validations for Active Storage