better_record 0.14.6 → 0.15.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b3b47c93ce607424d77c2831e43ce7c95891b5aa20694a945f0730a315dec04
4
- data.tar.gz: 459521050b68f43271c3317be0f5edff448b07bf3f8cb74041c204846aadc657
3
+ metadata.gz: ce8484d1edf7ffd679a8c3e2b6cfedb3602a979cad7b63930505c53f7fbf2c44
4
+ data.tar.gz: 2b7a2ba41a6670d710ac47fc8eab490f7147d005b035abdb50dc78ba1f4478dc
5
5
  SHA512:
6
- metadata.gz: cafd6735f8bfff8a9e40bae9c8d3c9bdcab3a60f92757e19e2c4bc3238fe830669cbaff5d93d4ec132660212b35b19835398e388ea5fab6662b6eb7c66254d62
7
- data.tar.gz: 2835b9855fcb0c62e3d898169af895b79ec7d7c4c434f07b07c65681b7f82b1bd60a7afba19b9463bfe7ff90ed6180375d38c404584daa7215bc51947536935c
6
+ metadata.gz: c9c42297037f1e6f78b009631d7790502bc39c3bdff5401c8f9ee64d36c746ddbbd6274abb49b815ae236a11d8378b8fecd7a0b2062d6a705c3e820b4117452e
7
+ data.tar.gz: 5956669acd747dfdc77fc6feaeb9cd6e56d2b4bb51483e66da7e563bc9fb6e61b6a86b2af4f36974372b65c7e1a514dc08532f27c841c2b4b4e1db845127b573
@@ -0,0 +1,23 @@
1
+ module BetterRecord
2
+ class ResizeBlobImageJob < ApplicationJob
3
+ queue_as :default
4
+
5
+ def perform(**params)
6
+ if record = params[:model].constantize.find_by(params[:query].deep_symbolize_keys)
7
+ blob = record.__send__(params[:attachment]).blob
8
+ tmp = Tempfile.new
9
+ tmp.binmode
10
+ tmp.write(blob.service.download(blob.variant(params[:options]).processed.key))
11
+ tmp.flush
12
+ tmp.rewind
13
+ record.__send__(params[:attachment]).attach(
14
+ io: tmp,
15
+ filename: blob.filename,
16
+ content_type: blob.content_type
17
+ )
18
+ blob.purge_later
19
+ params[:backup_action].present? && record.__send__(params[:backup_action])
20
+ end
21
+ end
22
+ end
23
+ end
@@ -16,6 +16,7 @@ module BetterRecord
16
16
  min_image_size: nil,
17
17
  max_image_size: 500.kilobytes,
18
18
  shrink_large_image: false,
19
+ shrink_later: false,
19
20
  **opts
20
21
  )
21
22
  # == Constants ============================================================
@@ -59,16 +60,21 @@ module BetterRecord
59
60
 
60
61
  define_method :valid_image_size do
61
62
  if max_image_size && __send__(avatar_name).blob.byte_size > max_image_size
62
- if shrink_large_image
63
+ if shrink_large_image.present?
63
64
  begin
64
65
  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
66
+ @copy_later = true
67
+ ResizeBlobImageJob.
68
+ __send__ (shrink_later ? :perform_later : :perform_now), {
69
+ model: self.class.to_s,
70
+ query: {id: self.id},
71
+ attachment: avatar_name,
72
+ backup_action: :"cache_current_#{avatar_name}",
73
+ options: shrink_large_image
74
+ }
71
75
  rescue
76
+ puts $!.message
77
+ puts $!.backtrace
72
78
  return false
73
79
  end
74
80
  else
@@ -86,7 +92,7 @@ module BetterRecord
86
92
  return unless __send__(avatar_name).attached?
87
93
 
88
94
  if valid_image_format && valid_image_size
89
- __send__(:"cache_current_#{avatar_name}")
95
+ __send__(:"cache_current_#{avatar_name}") unless @copy_later
90
96
  else
91
97
  purge(__send__(avatar_name))
92
98
  __send__(:"load_last_#{avatar_name}") if __send__(:"last_#{avatar_name}").attached?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BetterRecord
4
- VERSION = '0.14.6'
4
+ VERSION = '0.15.0'
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.6
4
+ version: 0.15.0
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-12-27 00:00:00.000000000 Z
11
+ date: 2018-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -235,6 +235,7 @@ files:
235
235
  - app/helpers/better_record/application_helper.rb
236
236
  - app/helpers/better_record/table_sizes_helper.rb
237
237
  - app/jobs/better_record/application_job.rb
238
+ - app/jobs/better_record/resize_blob_image_job.rb
238
239
  - app/mailers/better_record/application_mailer.rb
239
240
  - app/models/better_record/base.rb
240
241
  - app/models/better_record/current.rb