shrine 1.4.2 → 2.0.0
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/README.md +236 -234
- data/doc/changing_location.md +6 -4
- data/doc/creating_storages.md +4 -4
- data/doc/design.md +223 -0
- data/doc/migrating_storage.md +6 -11
- data/doc/regenerating_versions.md +22 -40
- data/lib/shrine.rb +60 -77
- data/lib/shrine/plugins/activerecord.rb +37 -14
- data/lib/shrine/plugins/background_helpers.rb +1 -0
- data/lib/shrine/plugins/backgrounding.rb +49 -37
- data/lib/shrine/plugins/backup.rb +6 -4
- data/lib/shrine/plugins/cached_attachment_data.rb +5 -5
- data/lib/shrine/plugins/data_uri.rb +9 -9
- data/lib/shrine/plugins/default_storage.rb +4 -4
- data/lib/shrine/plugins/default_url.rb +7 -1
- data/lib/shrine/plugins/default_url_options.rb +1 -1
- data/lib/shrine/plugins/delete_promoted.rb +2 -2
- data/lib/shrine/plugins/delete_raw.rb +4 -4
- data/lib/shrine/plugins/determine_mime_type.rb +50 -43
- data/lib/shrine/plugins/direct_upload.rb +10 -20
- data/lib/shrine/plugins/download_endpoint.rb +16 -13
- data/lib/shrine/plugins/dynamic_storage.rb +4 -12
- data/lib/shrine/plugins/included.rb +6 -19
- data/lib/shrine/plugins/keep_files.rb +4 -4
- data/lib/shrine/plugins/logging.rb +4 -4
- data/lib/shrine/plugins/migration_helpers.rb +37 -34
- data/lib/shrine/plugins/moving.rb +19 -32
- data/lib/shrine/plugins/parallelize.rb +5 -5
- data/lib/shrine/plugins/pretty_location.rb +2 -6
- data/lib/shrine/plugins/remote_url.rb +31 -43
- data/lib/shrine/plugins/remove_attachment.rb +5 -5
- data/lib/shrine/plugins/remove_invalid.rb +1 -1
- data/lib/shrine/plugins/restore_cached_data.rb +4 -10
- data/lib/shrine/plugins/sequel.rb +46 -21
- data/lib/shrine/plugins/store_dimensions.rb +19 -20
- data/lib/shrine/plugins/upload_options.rb +11 -9
- data/lib/shrine/plugins/validation_helpers.rb +3 -3
- data/lib/shrine/plugins/versions.rb +18 -3
- data/lib/shrine/storage/file_system.rb +9 -11
- data/lib/shrine/storage/linter.rb +1 -7
- data/lib/shrine/storage/s3.rb +25 -19
- data/lib/shrine/version.rb +3 -3
- data/shrine.gemspec +13 -3
- metadata +28 -9
- data/lib/shrine/plugins/delete_uploaded.rb +0 -3
- data/lib/shrine/plugins/keep_location.rb +0 -46
- data/lib/shrine/plugins/restore_cached.rb +0 -3
@@ -91,10 +91,9 @@ class Shrine
|
|
91
91
|
# : By default empty folders inside the directory are automatically
|
92
92
|
# deleted, but if it happens that it causes too much load on the
|
93
93
|
# filesystem, you can set this option to `false`.
|
94
|
-
def initialize(directory, prefix: nil, host: nil, clean: true, permissions: nil
|
95
|
-
if prefix
|
96
|
-
|
97
|
-
@prefix = Pathname(relative(prefix || subdirectory))
|
94
|
+
def initialize(directory, prefix: nil, host: nil, clean: true, permissions: nil)
|
95
|
+
if prefix
|
96
|
+
@prefix = Pathname(relative(prefix))
|
98
97
|
@directory = Pathname(directory).join(@prefix)
|
99
98
|
else
|
100
99
|
@directory = Pathname(directory)
|
@@ -109,7 +108,7 @@ class Shrine
|
|
109
108
|
end
|
110
109
|
|
111
110
|
# Copies the file into the given location.
|
112
|
-
def upload(io, id,
|
111
|
+
def upload(io, id, shrine_metadata: {}, **upload_options)
|
113
112
|
IO.copy_stream(io, path!(id))
|
114
113
|
path(id).chmod(permissions) if permissions
|
115
114
|
end
|
@@ -121,7 +120,7 @@ class Shrine
|
|
121
120
|
|
122
121
|
# Moves the file to the given location. This gets called by the "moving"
|
123
122
|
# plugin.
|
124
|
-
def move(io, id,
|
123
|
+
def move(io, id, shrine_metadata: {}, **upload_options)
|
125
124
|
if io.respond_to?(:path)
|
126
125
|
FileUtils.mv io.path, path!(id)
|
127
126
|
else
|
@@ -168,16 +167,15 @@ class Shrine
|
|
168
167
|
host ? host + path : path
|
169
168
|
end
|
170
169
|
|
171
|
-
#
|
172
|
-
#
|
173
|
-
#
|
174
|
-
def clear!(
|
170
|
+
# Deletes all files from the #directory. If `:older_than` is passed in (a
|
171
|
+
# `Time` object), deletes all files which were last modified before that
|
172
|
+
# time.
|
173
|
+
def clear!(older_than: nil)
|
175
174
|
if older_than
|
176
175
|
directory.find do |path|
|
177
176
|
path.mtime < older_than ? path.rmtree : Find.prune
|
178
177
|
end
|
179
178
|
else
|
180
|
-
raise Shrine::Confirm unless confirm == :confirm
|
181
179
|
directory.rmtree
|
182
180
|
directory.mkpath
|
183
181
|
directory.chmod(permissions) if permissions
|
@@ -118,14 +118,8 @@ class Shrine
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def lint_clear(id)
|
121
|
-
storage.clear!
|
121
|
+
storage.clear!
|
122
122
|
error :clear!, "file still #exists? after clearing" if storage.exists?(id)
|
123
|
-
|
124
|
-
begin
|
125
|
-
storage.clear!
|
126
|
-
error :clear!, "should raise Shrine::Confirm if :confirm is not passed in"
|
127
|
-
rescue Shrine::Confirm
|
128
|
-
end
|
129
123
|
end
|
130
124
|
|
131
125
|
private
|
data/lib/shrine/storage/s3.rb
CHANGED
@@ -116,10 +116,10 @@ class Shrine
|
|
116
116
|
#
|
117
117
|
# It assigns the correct "Content-Type" taken from the MIME type, because
|
118
118
|
# by default S3 sets everything to "application/octet-stream".
|
119
|
-
def upload(io, id,
|
120
|
-
options = {content_type:
|
119
|
+
def upload(io, id, shrine_metadata: {}, **upload_options)
|
120
|
+
options = {content_type: shrine_metadata["mime_type"]}
|
121
|
+
options.update(@upload_options)
|
121
122
|
options.update(upload_options)
|
122
|
-
options.update(metadata.delete("s3") || {})
|
123
123
|
|
124
124
|
if copyable?(io)
|
125
125
|
copy(io, id, **options)
|
@@ -171,34 +171,40 @@ class Shrine
|
|
171
171
|
|
172
172
|
# Returns the presigned URL to the file.
|
173
173
|
#
|
174
|
+
# :public
|
175
|
+
# : Creates an unsigned version of the URL (the permissions on the S3
|
176
|
+
# bucket need to be modified to allow public URLs).
|
177
|
+
#
|
174
178
|
# :download
|
175
179
|
# : If set to `true`, creates a "forced download" link, which means that
|
176
180
|
# the browser will never display the file and always ask the user to
|
177
181
|
# download it.
|
178
182
|
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
# permissions on the S3 bucket).
|
182
|
-
#
|
183
|
-
# All other options are forwarded to [`Aws::S3::Object#presigned_url`].
|
183
|
+
# All other options are forwarded to [`Aws::S3::Object#presigned_url`] or
|
184
|
+
# [`Aws::S3::Object#public_url`].
|
184
185
|
#
|
185
186
|
# [`Aws::S3::Object#presigned_url`]: http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Object.html#presigned_url-instance_method
|
187
|
+
# [`Aws::S3::Object#public_url`]: http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Object.html#public_url-instance_method
|
186
188
|
def url(id, download: nil, public: nil, **options)
|
187
|
-
if
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
else
|
192
|
-
object(id).public_url(**options)
|
193
|
-
end
|
189
|
+
options[:response_content_disposition] = "attachment" if download
|
190
|
+
|
191
|
+
if public
|
192
|
+
url = object(id).public_url(**options)
|
194
193
|
else
|
195
|
-
|
194
|
+
url = object(id).presigned_url(:get, **options)
|
195
|
+
end
|
196
|
+
|
197
|
+
if host
|
198
|
+
uri = URI.parse(url)
|
199
|
+
uri.path = uri.path.match(/^\/#{bucket.name}/).post_match unless uri.host.include?(bucket.name)
|
200
|
+
url = URI.join(host, uri.request_uri).to_s
|
196
201
|
end
|
202
|
+
|
203
|
+
url
|
197
204
|
end
|
198
205
|
|
199
|
-
# Deletes all files from the storage
|
200
|
-
def clear!
|
201
|
-
raise Shrine::Confirm unless confirm == :confirm
|
206
|
+
# Deletes all files from the storage.
|
207
|
+
def clear!
|
202
208
|
bucket.object_versions(prefix: prefix).delete
|
203
209
|
end
|
204
210
|
|
data/lib/shrine/version.rb
CHANGED
data/shrine.gemspec
CHANGED
@@ -6,8 +6,17 @@ Gem::Specification.new do |gem|
|
|
6
6
|
|
7
7
|
gem.required_ruby_version = ">= 2.1"
|
8
8
|
|
9
|
-
gem.summary = "Toolkit for file uploads in Ruby"
|
10
|
-
gem.description =
|
9
|
+
gem.summary = "Toolkit for handling file uploads in Ruby"
|
10
|
+
gem.description = <<-END
|
11
|
+
Shrine is a toolkit for handling file uploads in Ruby. It supports uploading,
|
12
|
+
processing and deleting IO objects, backed by a storage adapter. It uses
|
13
|
+
efficient streaming to minimize memory usage.
|
14
|
+
|
15
|
+
Shrine comes with a high-level attachment interface for attaching uploaded
|
16
|
+
files to database records, saving their location and metadata to a database
|
17
|
+
column, and tying them to record's lifecycle.
|
18
|
+
END
|
19
|
+
|
11
20
|
gem.homepage = "https://github.com/janko-m/shrine"
|
12
21
|
gem.authors = ["Janko Marohnić"]
|
13
22
|
gem.email = ["janko.marohnic@gmail.com"]
|
@@ -16,7 +25,7 @@ Gem::Specification.new do |gem|
|
|
16
25
|
gem.files = Dir["README.md", "LICENSE.txt", "lib/**/*.rb", "shrine.gemspec", "doc/*.md"]
|
17
26
|
gem.require_path = "lib"
|
18
27
|
|
19
|
-
gem.add_dependency "down", ">= 2.0
|
28
|
+
gem.add_dependency "down", ">= 2.2.0"
|
20
29
|
|
21
30
|
gem.add_development_dependency "rake", "~> 11.1"
|
22
31
|
gem.add_development_dependency "minitest", "~> 5.8"
|
@@ -25,6 +34,7 @@ Gem::Specification.new do |gem|
|
|
25
34
|
gem.add_development_dependency "webmock"
|
26
35
|
gem.add_development_dependency "rack-test_app"
|
27
36
|
gem.add_development_dependency "dotenv"
|
37
|
+
gem.add_development_dependency "shrine-memory"
|
28
38
|
|
29
39
|
gem.add_development_dependency "roda"
|
30
40
|
gem.add_development_dependency "mimemagic"
|
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:
|
4
|
+
version: 2.0.0
|
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-
|
11
|
+
date: 2016-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: down
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.0
|
19
|
+
version: 2.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.0
|
26
|
+
version: 2.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: shrine-memory
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: roda
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -248,7 +262,14 @@ dependencies:
|
|
248
262
|
- - ">="
|
249
263
|
- !ruby/object:Gem::Version
|
250
264
|
version: '0'
|
251
|
-
description:
|
265
|
+
description: |
|
266
|
+
Shrine is a toolkit for handling file uploads in Ruby. It supports uploading,
|
267
|
+
processing and deleting IO objects, backed by a storage adapter. It uses
|
268
|
+
efficient streaming to minimize memory usage.
|
269
|
+
|
270
|
+
Shrine comes with a high-level attachment interface for attaching uploaded
|
271
|
+
files to database records, saving their location and metadata to a database
|
272
|
+
column, and tying them to record's lifecycle.
|
252
273
|
email:
|
253
274
|
- janko.marohnic@gmail.com
|
254
275
|
executables: []
|
@@ -261,6 +282,7 @@ files:
|
|
261
282
|
- doc/changing_location.md
|
262
283
|
- doc/creating_plugins.md
|
263
284
|
- doc/creating_storages.md
|
285
|
+
- doc/design.md
|
264
286
|
- doc/direct_s3.md
|
265
287
|
- doc/migrating_storage.md
|
266
288
|
- doc/paperclip.md
|
@@ -279,7 +301,6 @@ files:
|
|
279
301
|
- lib/shrine/plugins/default_url_options.rb
|
280
302
|
- lib/shrine/plugins/delete_promoted.rb
|
281
303
|
- lib/shrine/plugins/delete_raw.rb
|
282
|
-
- lib/shrine/plugins/delete_uploaded.rb
|
283
304
|
- lib/shrine/plugins/determine_mime_type.rb
|
284
305
|
- lib/shrine/plugins/direct_upload.rb
|
285
306
|
- lib/shrine/plugins/download_endpoint.rb
|
@@ -287,7 +308,6 @@ files:
|
|
287
308
|
- lib/shrine/plugins/hooks.rb
|
288
309
|
- lib/shrine/plugins/included.rb
|
289
310
|
- lib/shrine/plugins/keep_files.rb
|
290
|
-
- lib/shrine/plugins/keep_location.rb
|
291
311
|
- lib/shrine/plugins/logging.rb
|
292
312
|
- lib/shrine/plugins/migration_helpers.rb
|
293
313
|
- lib/shrine/plugins/module_include.rb
|
@@ -301,7 +321,6 @@ files:
|
|
301
321
|
- lib/shrine/plugins/remote_url.rb
|
302
322
|
- lib/shrine/plugins/remove_attachment.rb
|
303
323
|
- lib/shrine/plugins/remove_invalid.rb
|
304
|
-
- lib/shrine/plugins/restore_cached.rb
|
305
324
|
- lib/shrine/plugins/restore_cached_data.rb
|
306
325
|
- lib/shrine/plugins/sequel.rb
|
307
326
|
- lib/shrine/plugins/store_dimensions.rb
|
@@ -336,6 +355,6 @@ rubyforge_project:
|
|
336
355
|
rubygems_version: 2.5.1
|
337
356
|
signing_key:
|
338
357
|
specification_version: 4
|
339
|
-
summary: Toolkit for file uploads in Ruby
|
358
|
+
summary: Toolkit for handling file uploads in Ruby
|
340
359
|
test_files: []
|
341
360
|
has_rdoc:
|
@@ -1,46 +0,0 @@
|
|
1
|
-
warn "The keep_location Shrine plugin is deprecated and will be removed in Shrine 2. " \
|
2
|
-
"You can easily implement the same behaviour in Shrine#generate_location."
|
3
|
-
|
4
|
-
class Shrine
|
5
|
-
module Plugins
|
6
|
-
# The keep_location plugin allows you to preserve locations when
|
7
|
-
# transferring files from one storage to another. This can be useful for
|
8
|
-
# debugging purposes or for backups.
|
9
|
-
#
|
10
|
-
# plugin :keep_location, :cache => :store
|
11
|
-
#
|
12
|
-
# The above will preserve location of cached files uploaded to store. More
|
13
|
-
# precisely, if a Shrine::UploadedFile from cache is begin uploaded to
|
14
|
-
# store, the stored file will have the same location as the cached file.
|
15
|
-
#
|
16
|
-
# The destination storage can also be specified as an array:
|
17
|
-
#
|
18
|
-
# plugin :keep_location, :cache => [:storage1, :storage2]
|
19
|
-
module KeepLocation
|
20
|
-
def self.configure(uploader, mappings = {})
|
21
|
-
uploader.opts[:keep_location_mappings] = mappings
|
22
|
-
end
|
23
|
-
|
24
|
-
module InstanceMethods
|
25
|
-
private
|
26
|
-
|
27
|
-
def get_location(io, context)
|
28
|
-
if !context[:location] && io.is_a?(UploadedFile) && keep_location?(io)
|
29
|
-
io.id
|
30
|
-
else
|
31
|
-
super
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def keep_location?(uploaded_file)
|
36
|
-
opts[:keep_location_mappings].any? do |source, destination|
|
37
|
-
source == uploaded_file.storage_key.to_sym &&
|
38
|
-
Array(destination).include?(self.storage_key)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
register_plugin(:keep_location, KeepLocation)
|
45
|
-
end
|
46
|
-
end
|
@@ -1,3 +0,0 @@
|
|
1
|
-
warn "The restore_cached Shrine plugin has been renamed to \"restore_cached_data\". Loading the plugin through \"restore_cached\" will not work in Shrine 2."
|
2
|
-
require "shrine/plugins/restore_cached_data"
|
3
|
-
Shrine::Plugins.register_plugin(:restore_cached, Shrine::Plugins::RestoreCachedData)
|