paperweight 0.2.0 → 1.0.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +4 -4
- data/README.md +4 -2
- data/lib/paperweight/hooks.rb +70 -0
- data/lib/paperweight/post_process_job.rb +2 -4
- data/lib/paperweight/version.rb +1 -1
- data/lib/paperweight.rb +3 -2
- metadata +2 -2
- data/lib/paperweight/hook.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f08760e0f79a70c76350131c65de6fcca3ed7a3366eeb3893d1f64b817ede4ee
|
4
|
+
data.tar.gz: 42df1435f059aab276345f12fac1c35fdce71b9bf237bd73163fa4ef3d87c5df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54348c7ce20c685556a8ad1aad6e8c62abee2916091f5120cdfa4c266c5a3790ecd0a0234ec3e18a7218fb2c402aaef20b0b4484d3363dbee7ae12acdf1aec76
|
7
|
+
data.tar.gz: 1176e2de7cab6b5d0f8eea6e76fbfad435cc2d06fcacb633286db19c56e3937cfbf0dcdde2d19b5ab43dadbd447c461d009a3cad0e8be13796a05917d0a48692
|
data/CHANGELOG.md
CHANGED
@@ -6,9 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.0.0] - 2018-08-15
|
10
|
+
### Changed
|
11
|
+
- Changed the expected column type of `#*_processing` from a boolean to string. This allows us to use it to store the URL from the `#*_url=` method so that it can be used in the meantime before the job finishes processing.
|
12
|
+
|
9
13
|
## [0.2.0] - 2018-08-15
|
10
14
|
### Added
|
11
15
|
- The ability to configure the `max_size` value (the maximum download size) using the `Paperweight.configure` method.
|
12
16
|
|
13
17
|
[Unreleased]: https://github.com/CultureHQ/client/compare/v0.2.0...HEAD
|
18
|
+
[v1.0.0]: https://github.com/CultureHQ/client/compare/v0.2.0...v1.0.0
|
14
19
|
[v0.2.0]: https://github.com/CultureHQ/client/compare/v0.1.2...v0.2.0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
paperweight (0.
|
4
|
+
paperweight (1.0.0)
|
5
5
|
paperclip (>= 5)
|
6
6
|
rails (>= 5)
|
7
7
|
|
@@ -71,11 +71,11 @@ GEM
|
|
71
71
|
marcel (0.3.2)
|
72
72
|
mimemagic (~> 0.3.2)
|
73
73
|
method_source (0.9.0)
|
74
|
-
mime-types (3.
|
74
|
+
mime-types (3.2.2)
|
75
75
|
mime-types-data (~> 3.2015)
|
76
|
-
mime-types-data (3.
|
76
|
+
mime-types-data (3.2018.0812)
|
77
77
|
mimemagic (0.3.2)
|
78
|
-
mini_mime (1.0.
|
78
|
+
mini_mime (1.0.1)
|
79
79
|
mini_portile2 (2.3.0)
|
80
80
|
minitest (5.11.3)
|
81
81
|
nio4r (2.3.1)
|
data/README.md
CHANGED
@@ -22,16 +22,18 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
Configure `Paperclip` as you normally would, according to their docs. Then, add an additional `*_processing`
|
25
|
+
Configure `Paperclip` as you normally would, according to their docs. Then, add an additional `*_processing` string field to the model for which you want to process attachments in the background, where `*` is the name of the attachment that you specified in your model's call to `has_attached_file`.
|
26
26
|
|
27
27
|
```ruby
|
28
28
|
class AddImageProcessingToPosts < ActiveRecord::Migration[5.2]
|
29
29
|
def change
|
30
|
-
add_column :posts, :image_processing, :
|
30
|
+
add_column :posts, :image_processing, :string
|
31
31
|
end
|
32
32
|
end
|
33
33
|
```
|
34
34
|
|
35
|
+
This column will be used to hold the temporary URL of the image that needs to be processed. It will override all calls to the `#url` method on `Paperclip` attachments until the processing is done so that there's no break in the visibility of the image.
|
36
|
+
|
35
37
|
Then, add the ability to update the `*_url` attribute from the controller.
|
36
38
|
|
37
39
|
```ruby
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Paperweight
|
4
|
+
# Overrides that hook into `paperclip` to add functionality.
|
5
|
+
module Hooks
|
6
|
+
# Overrides the `has_attached_file` method from `paperclip` so that
|
7
|
+
# `paperweight` can add extras when the macro is called.
|
8
|
+
module RecordHook
|
9
|
+
# Converts a parent name to its respective component child names.
|
10
|
+
class AttachmentName
|
11
|
+
attr_reader :name
|
12
|
+
|
13
|
+
def initialize(name)
|
14
|
+
@name = name
|
15
|
+
end
|
16
|
+
|
17
|
+
def processing
|
18
|
+
:"#{name}_processing"
|
19
|
+
end
|
20
|
+
|
21
|
+
def url
|
22
|
+
:"#{name}_url"
|
23
|
+
end
|
24
|
+
|
25
|
+
def url_eq
|
26
|
+
:"#{name}_url="
|
27
|
+
end
|
28
|
+
|
29
|
+
def url_attr
|
30
|
+
:"@#{name}_url"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def has_attached_file(name, *) # rubocop:disable Naming/PredicateName
|
35
|
+
super
|
36
|
+
|
37
|
+
name = AttachmentName.new(name)
|
38
|
+
attr_reader name.url
|
39
|
+
|
40
|
+
define_paperweight_setter_for(name)
|
41
|
+
define_paperweight_after_commit_for(name)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def define_paperweight_setter_for(name)
|
47
|
+
define_method(name.url_eq) do |value|
|
48
|
+
instance_variable_set(name.url_attr, value)
|
49
|
+
self[name.processing] = value
|
50
|
+
self.updated_at = Time.now if value
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def define_paperweight_after_commit_for(name)
|
55
|
+
after_commit if: name.url do
|
56
|
+
attachment_url = public_send(name.url)
|
57
|
+
PostProcessJob.perform_later(self, name.name.to_s, attachment_url)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Overrides the `url` method from `paperclip` so that `paperweight` can
|
63
|
+
# check the `image_processing` field and use that if it's still processing.
|
64
|
+
module AttachmentHook
|
65
|
+
def url(*)
|
66
|
+
instance.public_send(:"#{name}_processing") || super
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -8,10 +8,8 @@ module Paperweight
|
|
8
8
|
discard_on ActiveJob::DeserializationError
|
9
9
|
|
10
10
|
def perform(model, name, url)
|
11
|
-
|
12
|
-
|
13
|
-
:"#{name}_processing" => false
|
14
|
-
)
|
11
|
+
tempfile = Download.new.download(url)
|
12
|
+
model.update!(name => tempfile, :"#{name}_processing" => nil)
|
15
13
|
end
|
16
14
|
end
|
17
15
|
end
|
data/lib/paperweight/version.rb
CHANGED
data/lib/paperweight.rb
CHANGED
@@ -9,8 +9,9 @@ require 'active_job'
|
|
9
9
|
|
10
10
|
require 'paperweight/configuration'
|
11
11
|
require 'paperweight/download'
|
12
|
-
require 'paperweight/
|
12
|
+
require 'paperweight/hooks'
|
13
13
|
require 'paperweight/post_process_job'
|
14
14
|
require 'paperweight/version'
|
15
15
|
|
16
|
-
Paperclip::ClassMethods.prepend(Paperweight::
|
16
|
+
Paperclip::ClassMethods.prepend(Paperweight::Hooks::RecordHook)
|
17
|
+
Paperclip::Attachment.prepend(Paperweight::Hooks::AttachmentHook)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperweight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Deisz
|
@@ -143,7 +143,7 @@ files:
|
|
143
143
|
- lib/paperweight.rb
|
144
144
|
- lib/paperweight/configuration.rb
|
145
145
|
- lib/paperweight/download.rb
|
146
|
-
- lib/paperweight/
|
146
|
+
- lib/paperweight/hooks.rb
|
147
147
|
- lib/paperweight/post_process_job.rb
|
148
148
|
- lib/paperweight/version.rb
|
149
149
|
- paperweight.gemspec
|
data/lib/paperweight/hook.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Paperweight
|
4
|
-
# Overrides the `has_attached_file` method from `paperclip` so that
|
5
|
-
# `paperweight` can add extras when the macro is called.
|
6
|
-
module Hook
|
7
|
-
# Converts a parent name to its respective component child names.
|
8
|
-
class AttachmentName
|
9
|
-
attr_reader :name
|
10
|
-
|
11
|
-
def initialize(name)
|
12
|
-
@name = name
|
13
|
-
end
|
14
|
-
|
15
|
-
def processing
|
16
|
-
:"#{name}_processing"
|
17
|
-
end
|
18
|
-
|
19
|
-
def url
|
20
|
-
:"#{name}_url"
|
21
|
-
end
|
22
|
-
|
23
|
-
def url_eq
|
24
|
-
:"#{name}_url="
|
25
|
-
end
|
26
|
-
|
27
|
-
def url_attr
|
28
|
-
:"@#{name}_url"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def has_attached_file(name, *) # rubocop:disable Naming/PredicateName
|
33
|
-
super
|
34
|
-
|
35
|
-
name = AttachmentName.new(name)
|
36
|
-
attr_reader name.url
|
37
|
-
|
38
|
-
define_paperweight_setter_for(name)
|
39
|
-
define_paperweight_after_commit_for(name)
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def define_paperweight_setter_for(name)
|
45
|
-
define_method(name.url_eq) do |value|
|
46
|
-
instance_variable_set(name.url_attr, value)
|
47
|
-
self[name.processing] = value ? true : false
|
48
|
-
self.updated_at = Time.now if value
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def define_paperweight_after_commit_for(name)
|
53
|
-
after_commit if: name.url do
|
54
|
-
attachment_url = public_send(name.url)
|
55
|
-
PostProcessJob.perform_later(self, name.name.to_s, attachment_url)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|