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: 7e37c28c428a988cd2eeea6d47e91a5df0984430f43bf0fbdf53023fddc45ffb
4
- data.tar.gz: d49fda729a390605750dee0217e2fbce72cec21630ae356e8b55039050bdae70
3
+ metadata.gz: 4b3b47c93ce607424d77c2831e43ce7c95891b5aa20694a945f0730a315dec04
4
+ data.tar.gz: 459521050b68f43271c3317be0f5edff448b07bf3f8cb74041c204846aadc657
5
5
  SHA512:
6
- metadata.gz: 9aad0c0fb4ce9428bb3efc50053208b68eb8ad17ff10a0ac40cb9766c775c4e2201c0f9b71a1cca64f1009801dced21fc2c0ebc3ce8327538c606808205995ca
7
- data.tar.gz: 40e93541d5eea8bb9164f798136d0a17a5276db0546e20996c57057e3d7089440b8ef89386428f4cf6133a7dc47e93fa4c2558d81a6929b7b61943f72b325a56
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
- errors.add(avatar_name, "is too large, maximum #{ActiveSupport::NumberHelper.number_to_human_size(max_image_size)}")
62
- return false
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BetterRecord
4
- VERSION = '0.14.5'
4
+ VERSION = '0.14.6'
5
5
  end
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.5
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-10-12 00:00:00.000000000 Z
11
+ date: 2018-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails