shrine 2.4.0 → 2.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/testing.md +1 -1
- data/lib/shrine.rb +3 -3
- data/lib/shrine/plugins/remove_invalid.rb +4 -3
- data/lib/shrine/storage/file_system.rb +12 -8
- 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: 93c5aa709ec2574b80b2a5d3b62f1f6d5b2cd312
|
4
|
+
data.tar.gz: f6f13f2f4b24c6961a846634462c9d1aa2c16e7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 712eaa97b81d90b928b0e7967740d79e0f4320af5b67a811e8a991f0e91e103568f70cc08683aa5e38fd3235021869a5c8634f08d67d961971edacc0aa9cb5b9
|
7
|
+
data.tar.gz: fa531d81b429dbd94cfab836f50180aa6eed61e33eceaffe0b4d901398228cedfb19d9add18a0ebdb5c131d803b6c072a8e6972b9ea1c9cd9095f4da6e0f401f
|
data/doc/testing.md
CHANGED
@@ -80,7 +80,7 @@ Shrine.plugin :data_uri
|
|
80
80
|
```yml
|
81
81
|
# test/fixtures/photos.yml
|
82
82
|
photo:
|
83
|
-
image_data_uri: "data:image/png,<%= File.
|
83
|
+
image_data_uri: "data:image/png;base64,<%= Base64.encode64(File.binread("test/files/image.png")) %>"
|
84
84
|
```
|
85
85
|
|
86
86
|
## Background jobs
|
data/lib/shrine.rb
CHANGED
@@ -660,12 +660,12 @@ class Shrine
|
|
660
660
|
# Converts the UploadedFile to a data hash and writes it to the
|
661
661
|
# attribute.
|
662
662
|
def _set(uploaded_file)
|
663
|
-
|
663
|
+
data = convert_to_data(uploaded_file) if uploaded_file
|
664
|
+
write(data ? convert_before_write(data) : nil)
|
664
665
|
end
|
665
666
|
|
666
667
|
# Writes to the `<attachment>_data` attribute on the model instance.
|
667
668
|
def write(value)
|
668
|
-
value = convert_before_write(value) unless value.nil?
|
669
669
|
record.send(:"#{data_attribute}=", value)
|
670
670
|
end
|
671
671
|
|
@@ -773,7 +773,7 @@ class Shrine
|
|
773
773
|
if storage.respond_to?(:download)
|
774
774
|
storage.download(id)
|
775
775
|
else
|
776
|
-
tempfile = Tempfile.new(["shrine",
|
776
|
+
tempfile = Tempfile.new(["shrine", ".#{extension}"], binmode: true)
|
777
777
|
open { |io| IO.copy_stream(io, tempfile.path) }
|
778
778
|
tempfile.tap(&:open)
|
779
779
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
class Shrine
|
2
2
|
module Plugins
|
3
3
|
# The `remove_invalid` plugin automatically deletes a cached file if it was
|
4
|
-
# invalid and deassigns it from the record.
|
4
|
+
# invalid and deassigns it from the record. If there was a previous file
|
5
|
+
# attached, it will be assigned back, otherwise `nil` will be assigned.
|
5
6
|
#
|
6
7
|
# plugin :remove_invalid
|
7
8
|
module RemoveInvalid
|
@@ -9,9 +10,9 @@ class Shrine
|
|
9
10
|
def validate
|
10
11
|
super
|
11
12
|
ensure
|
12
|
-
if errors.any? &&
|
13
|
+
if errors.any? && cached?
|
13
14
|
_delete(get, action: :validate)
|
14
|
-
_set(
|
15
|
+
_set(@old)
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require "down"
|
2
|
-
|
3
1
|
require "fileutils"
|
4
2
|
require "pathname"
|
5
3
|
|
@@ -48,7 +46,7 @@ class Shrine
|
|
48
46
|
# the following in a periodic Rake task:
|
49
47
|
#
|
50
48
|
# file_system = Shrine.storages[:cache]
|
51
|
-
# file_system.clear!(older_than:
|
49
|
+
# file_system.clear!(older_than: Time.now - 7*24*60*60) # delete files older than 1 week
|
52
50
|
#
|
53
51
|
# ## Permissions
|
54
52
|
#
|
@@ -122,11 +120,6 @@ class Shrine
|
|
122
120
|
path(id).chmod(permissions) if permissions
|
123
121
|
end
|
124
122
|
|
125
|
-
# Downloads the file from the given location, and returns a `Tempfile`.
|
126
|
-
def download(id)
|
127
|
-
open(id) { |file| Down.copy_to_tempfile(id, file) }
|
128
|
-
end
|
129
|
-
|
130
123
|
# Moves the file to the given location. This gets called by the `moving`
|
131
124
|
# plugin.
|
132
125
|
def move(io, id, shrine_metadata: {}, **upload_options)
|
@@ -189,6 +182,17 @@ class Shrine
|
|
189
182
|
end
|
190
183
|
end
|
191
184
|
|
185
|
+
# Catches the deprecated `#download` method.
|
186
|
+
def method_missing(name, *args)
|
187
|
+
if name == :download
|
188
|
+
warn "Shrine::Storage::FileSystem#download is deprecated and will be removed in Shrine 3."
|
189
|
+
require "down"
|
190
|
+
open(id) { |file| Down.copy_to_tempfile(id, file) }
|
191
|
+
else
|
192
|
+
super
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
192
196
|
protected
|
193
197
|
|
194
198
|
# Returns the full path to the file.
|
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: 2.4.
|
4
|
+
version: 2.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-10-
|
11
|
+
date: 2016-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: down
|