better_record 0.14.5 → 0.14.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b3b47c93ce607424d77c2831e43ce7c95891b5aa20694a945f0730a315dec04
|
4
|
+
data.tar.gz: 459521050b68f43271c3317be0f5edff448b07bf3f8cb74041c204846aadc657
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cafd6735f8bfff8a9e40bae9c8d3c9bdcab3a60f92757e19e2c4bc3238fe830669cbaff5d93d4ec132660212b35b19835398e388ea5fab6662b6eb7c66254d62
|
7
|
+
data.tar.gz: 2835b9855fcb0c62e3d898169af895b79ec7d7c4c434f07b07c65681b7f82b1bd60a7afba19b9463bfe7ff90ed6180375d38c404584daa7215bc51947536935c
|
@@ -15,6 +15,7 @@ module BetterRecord
|
|
15
15
|
image_validator: :valid_image,
|
16
16
|
min_image_size: nil,
|
17
17
|
max_image_size: 500.kilobytes,
|
18
|
+
shrink_large_image: false,
|
18
19
|
**opts
|
19
20
|
)
|
20
21
|
# == Constants ============================================================
|
@@ -58,8 +59,22 @@ module BetterRecord
|
|
58
59
|
|
59
60
|
define_method :valid_image_size do
|
60
61
|
if max_image_size && __send__(avatar_name).blob.byte_size > max_image_size
|
61
|
-
|
62
|
-
|
62
|
+
if shrink_large_image
|
63
|
+
begin
|
64
|
+
blob = __send__(avatar_name).blob
|
65
|
+
__send__(avatar_name).attach(
|
66
|
+
io: open(Rails.application.routes.url_helpers.url_for(blob.variant(resize: shrink_large_image))),
|
67
|
+
filename: blob.filename,
|
68
|
+
content_type: blob.content_type
|
69
|
+
)
|
70
|
+
blob.purge
|
71
|
+
rescue
|
72
|
+
return false
|
73
|
+
end
|
74
|
+
else
|
75
|
+
errors.add(avatar_name, "is too large, maximum #{ActiveSupport::NumberHelper.number_to_human_size(max_image_size)}")
|
76
|
+
return false
|
77
|
+
end
|
63
78
|
elsif min_image_size && __send__(avatar_name).blob.byte_size < min_image_size
|
64
79
|
errors.add(avatar_name, "is too small, minimum #{ActiveSupport::NumberHelper.number_to_human_size(min_image_size)}")
|
65
80
|
return false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: better_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sampson Crowley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|