shrine 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of shrine might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/doc/creating_storages.md +3 -0
- data/lib/shrine/plugins/activerecord.rb +12 -6
- data/lib/shrine/plugins/download_endpoint.rb +4 -4
- data/lib/shrine/plugins/sequel.rb +8 -7
- data/lib/shrine/plugins/versions.rb +1 -1
- data/lib/shrine/storage/linter.rb +1 -0
- data/lib/shrine/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a38bb3cd054c90665a75f94355bdb28ae598591
|
4
|
+
data.tar.gz: eda94865fdc8f5fbcdff3464015a77e5d8bcfd45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9160317e038ce1e401b716e49a812ef513ad3ff1cd9cc1a6663b71c3523f948db79c126e187615067e8af8f2436f495c5de3308a41cd27091ba3057dbc8c9e8a
|
7
|
+
data.tar.gz: da114a5953c31b3868f1bbb31e385b572919cb8ca854ecb1601b5c85a90336b7629628230a5b1c287c6f1b303ac17105b18ff6ad7660bf10fa33fd471f2c3d67
|
data/doc/creating_storages.md
CHANGED
@@ -111,6 +111,9 @@ class Shrine
|
|
111
111
|
end
|
112
112
|
```
|
113
113
|
|
114
|
+
You should also yield the total filesize as the second argument, so that
|
115
|
+
download_endpoint can set `Content-Length` before it starts streaming.
|
116
|
+
|
114
117
|
## Moving
|
115
118
|
|
116
119
|
If your storage can move files, you can add 2 additional methods, and they will
|
@@ -25,8 +25,10 @@ class Shrine
|
|
25
25
|
# `after_commit` callbacks won't get called, so in order to test uploading
|
26
26
|
# you should first disable these transactions for those tests.
|
27
27
|
#
|
28
|
-
# If you want to put some parts of this lifecycle into a background job,
|
29
|
-
# the backgrounding plugin.
|
28
|
+
# If you want to put some parts of this lifecycle into a background job,
|
29
|
+
# see the backgrounding plugin. In that case you might want to use
|
30
|
+
# ActiveRecord's [optimistic locking] to eliminate the chance of race
|
31
|
+
# conditions.
|
30
32
|
#
|
31
33
|
# Additionally, any Shrine validation errors will be added to
|
32
34
|
# ActiveRecord's errors upon validation. If you want to validate presence
|
@@ -36,6 +38,8 @@ class Shrine
|
|
36
38
|
# include ImageUploader[:avatar]
|
37
39
|
# validates_presence_of :avatar
|
38
40
|
# end
|
41
|
+
#
|
42
|
+
# [optimistic locking]: http://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html
|
39
43
|
module Activerecord
|
40
44
|
module AttachmentMethods
|
41
45
|
def included(model)
|
@@ -76,11 +80,13 @@ class Shrine
|
|
76
80
|
# Updates the current attachment with the new one, unless the current
|
77
81
|
# attachment has changed.
|
78
82
|
def update(uploaded_file)
|
79
|
-
record.
|
80
|
-
.
|
81
|
-
.
|
82
|
-
|
83
|
+
if record.send("#{name}_data") == record.reload.send("#{name}_data")
|
84
|
+
record.send("#{name}_data=", uploaded_file.to_json)
|
85
|
+
record.save(validate: false)
|
86
|
+
end
|
83
87
|
rescue ::ActiveRecord::RecordNotFound
|
88
|
+
rescue ::ActiveRecord::StaleObjectError
|
89
|
+
retry
|
84
90
|
end
|
85
91
|
end
|
86
92
|
end
|
@@ -3,9 +3,9 @@ require "roda"
|
|
3
3
|
class Shrine
|
4
4
|
module Plugins
|
5
5
|
# The download_endpoint plugin provides a [Roda] endpoint for downloading
|
6
|
-
# uploaded files from specified storages. This
|
7
|
-
# your storages aren't accessible over URL (e.g. database storages) or
|
8
|
-
# you want to authenticate your downloads.
|
6
|
+
# uploaded files from specified storages. This can be useful when files
|
7
|
+
# from your storages aren't accessible over URL (e.g. database storages) or
|
8
|
+
# if you want to authenticate your downloads.
|
9
9
|
#
|
10
10
|
# plugin :download_endpoint, storages: [:store], prefix: "attachments"
|
11
11
|
#
|
@@ -21,7 +21,7 @@ class Shrine
|
|
21
21
|
# to the endpoint for specified storages, so it's not needed to change the
|
22
22
|
# code:
|
23
23
|
#
|
24
|
-
# user.
|
24
|
+
# user.avatar.url #=> "/attachments/store/sdg0lsf8.jpg"
|
25
25
|
#
|
26
26
|
# :storages
|
27
27
|
# : An array of storage keys which the download endpoint should be used for.
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require "sequel"
|
2
2
|
|
3
|
+
Sequel::Model.plugin :instance_filters
|
4
|
+
|
3
5
|
class Shrine
|
4
6
|
module Plugins
|
5
7
|
# The sequel plugin extends the "attachment" interface with support for
|
@@ -19,8 +21,8 @@ class Shrine
|
|
19
21
|
# so that `after_commit` and `after_destroy_commit` callbacks get properly
|
20
22
|
# called.
|
21
23
|
#
|
22
|
-
# If you want to put some parts of this lifecycle into a background job,
|
23
|
-
# the backgrounding plugin.
|
24
|
+
# If you want to put some parts of this lifecycle into a background job,
|
25
|
+
# see the backgrounding plugin.
|
24
26
|
#
|
25
27
|
# Additionally, any Shrine validation errors will added to Sequel's
|
26
28
|
# errors upon validation. Note that if you want to validate presence of the
|
@@ -74,11 +76,10 @@ class Shrine
|
|
74
76
|
# Updates the current attachment with the new one, unless the current
|
75
77
|
# attachment has changed.
|
76
78
|
def update(uploaded_file)
|
77
|
-
record.
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
rescue ::Sequel::Error
|
79
|
+
record.instance_filter(:"#{name}_data" => record.send("#{name}_data"))
|
80
|
+
record.send("#{name}_data=", uploaded_file.to_json)
|
81
|
+
record.save(validate: false)
|
82
|
+
rescue ::Sequel::NoExistingObject
|
82
83
|
end
|
83
84
|
|
84
85
|
# Support for Postgres JSON columns.
|
@@ -44,7 +44,7 @@ class Shrine
|
|
44
44
|
# user.avatar[:medium].width #=> 500
|
45
45
|
# user.avatar[:small].width #=> 300
|
46
46
|
#
|
47
|
-
# You probably want to load the
|
47
|
+
# You probably want to load the delete_raw plugin to automatically
|
48
48
|
# delete processed files after they have been uploaded.
|
49
49
|
#
|
50
50
|
# The plugin also extends the `avatar_url` method to accept versions:
|
@@ -95,6 +95,7 @@ class Shrine
|
|
95
95
|
|
96
96
|
if Array(streamed.first).size == 2
|
97
97
|
error :stream, "yielded content length isn't a number" if !content_length.is_a?(Integer)
|
98
|
+
error :stream, "yielded chunks don't sum up to given content length" if content_length != chunks.inject("", :+).length
|
98
99
|
end
|
99
100
|
end
|
100
101
|
|
data/lib/shrine/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shrine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: down
|