shrine 2.19.1 → 2.19.2
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 +5 -5
- data/CHANGELOG.md +8 -0
- data/doc/plugins/default_url_options.md +1 -1
- data/lib/shrine.rb +2 -2
- data/lib/shrine/plugins/activerecord.rb +6 -4
- data/lib/shrine/plugins/default_url_options.rb +1 -1
- data/lib/shrine/plugins/infer_extension.rb +2 -4
- data/lib/shrine/plugins/pretty_location.rb +2 -2
- data/lib/shrine/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 14cd1140359997859d3f25aa72f22d425e778f7cfec37af3570690a45985f9d3
|
4
|
+
data.tar.gz: 1e2b2f745d676377b6eaab0169290475feb1735583331c52f397e6adbe9d7a7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e2c323641f065c9cca255dc4d036404ec3c0e18ec55632f2ce73351d166e08767720c77660090cd41f225028762f9af6b7559dc0ebc94355e3741dcd6f06a52
|
7
|
+
data.tar.gz: 8b1666efb1bdd5e4d4e06376398f2d82e60aab9e4a1113570bd72c790d51b0ee6d4370ee1465cea32ae43d8d7e62610408b45999fa504bd8cb817d34435bfd2d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 2.19.2 (2018-07-25)
|
2
|
+
|
3
|
+
* `default_url_options` – Allow deleting passed options when using a block (@janko)
|
4
|
+
|
5
|
+
* `activerecord` – Make it work with ActiveRecord 3 (@texpert)
|
6
|
+
|
7
|
+
* `infer_extension` – Fix compatibility with `pretty_location` plugin (@janko)
|
8
|
+
|
1
9
|
## 2.19.1 (2018-07-20)
|
2
10
|
|
3
11
|
* Bring back support for Ruby 2.3 (@janko)
|
@@ -13,7 +13,7 @@ which will receive the UploadedFile object along with any options that were
|
|
13
13
|
passed to `UploadedFile#url`.
|
14
14
|
|
15
15
|
```rb
|
16
|
-
plugin :default_url_options, store: -> (io,
|
16
|
+
plugin :default_url_options, store: -> (io, options) do
|
17
17
|
{ response_content_disposition: ContentDisposition.attachment(io.original_filename) }
|
18
18
|
end
|
19
19
|
```
|
data/lib/shrine.rb
CHANGED
@@ -244,7 +244,7 @@ class Shrine
|
|
244
244
|
# file extension. Can be overriden in uploaders for generating custom
|
245
245
|
# location.
|
246
246
|
def generate_location(io, context = {})
|
247
|
-
basic_location(io)
|
247
|
+
basic_location(io, metadata: context[:metadata] || {})
|
248
248
|
end
|
249
249
|
|
250
250
|
# Extracts filename, size and MIME type from the file, which is later
|
@@ -337,7 +337,7 @@ class Shrine
|
|
337
337
|
end
|
338
338
|
|
339
339
|
# Generates a basic location for an uploaded file
|
340
|
-
def basic_location(io)
|
340
|
+
def basic_location(io, metadata:)
|
341
341
|
extension = ".#{io.extension}" if io.is_a?(UploadedFile) && io.extension
|
342
342
|
extension ||= File.extname(extract_filename(io).to_s).downcase
|
343
343
|
basename = generate_uid(io)
|
@@ -35,12 +35,14 @@ class Shrine
|
|
35
35
|
attacher.save if attacher.changed?
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
[:create, :update].each do |action|
|
39
|
+
model.after_commit on: action do
|
40
|
+
attacher = send("#{name}_attacher")
|
41
|
+
attacher.finalize if attacher.changed?
|
42
|
+
end
|
41
43
|
end
|
42
44
|
|
43
|
-
model.after_commit on:
|
45
|
+
model.after_commit on: :destroy do
|
44
46
|
send("#{name}_attacher").destroy
|
45
47
|
end
|
46
48
|
end
|
@@ -14,7 +14,7 @@ class Shrine
|
|
14
14
|
module FileMethods
|
15
15
|
def url(**options)
|
16
16
|
default_options = default_url_options
|
17
|
-
default_options = default_options.call(self,
|
17
|
+
default_options = default_options.call(self, options) if default_options.respond_to?(:call)
|
18
18
|
default_options ||= {}
|
19
19
|
|
20
20
|
super(default_options.merge(options))
|
@@ -53,14 +53,12 @@ class Shrine
|
|
53
53
|
end
|
54
54
|
|
55
55
|
module InstanceMethods
|
56
|
-
def
|
57
|
-
mime_type = (context[:metadata] || {})["mime_type"]
|
58
|
-
|
56
|
+
def basic_location(io, metadata:)
|
59
57
|
location = super
|
60
58
|
current_extension = File.extname(location)
|
61
59
|
|
62
60
|
if current_extension.empty? || opts[:infer_extension][:force]
|
63
|
-
inferred_extension = infer_extension(mime_type)
|
61
|
+
inferred_extension = infer_extension(metadata["mime_type"])
|
64
62
|
location = location.chomp(current_extension) << inferred_extension unless inferred_extension.empty?
|
65
63
|
end
|
66
64
|
|
@@ -16,13 +16,13 @@ class Shrine
|
|
16
16
|
pretty_location(io, context)
|
17
17
|
end
|
18
18
|
|
19
|
-
def pretty_location(io, name: nil, record: nil, version: nil, identifier: nil, **)
|
19
|
+
def pretty_location(io, name: nil, record: nil, version: nil, identifier: nil, metadata: {}, **)
|
20
20
|
if record
|
21
21
|
namespace = record_namespace(record)
|
22
22
|
identifier ||= record_identifier(record)
|
23
23
|
end
|
24
24
|
|
25
|
-
basename = basic_location(io)
|
25
|
+
basename = basic_location(io, metadata: metadata)
|
26
26
|
basename = "#{version}-#{basename}" if version
|
27
27
|
|
28
28
|
[*namespace, *identifier, *name, basename].join("/")
|
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.19.
|
4
|
+
version: 2.19.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: down
|
@@ -566,8 +566,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
566
566
|
- !ruby/object:Gem::Version
|
567
567
|
version: '0'
|
568
568
|
requirements: []
|
569
|
-
|
570
|
-
rubygems_version: 2.5.2.3
|
569
|
+
rubygems_version: 3.0.3
|
571
570
|
signing_key:
|
572
571
|
specification_version: 4
|
573
572
|
summary: Toolkit for file attachments in Ruby applications
|