shrine 1.3.0 → 1.4.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.

@@ -130,12 +130,13 @@ class Shrine
130
130
 
131
131
  # Downloads the file from S3, and returns a `Tempfile`.
132
132
  def download(id)
133
- Down.download(url(id))
133
+ Down.download(url(id), ssl_ca_cert: Aws.config[:ssl_ca_bundle])
134
134
  end
135
135
 
136
136
  # Streams the object from S3, yielding downloaded chunks.
137
137
  def stream(id)
138
- object(id).get { |chunk| yield chunk }
138
+ object = object(id)
139
+ object.get { |chunk| yield chunk, object.content_length }
139
140
  end
140
141
 
141
142
  # Alias for #download.
@@ -191,14 +192,14 @@ class Shrine
191
192
  object(id).public_url(**options)
192
193
  end
193
194
  else
194
- URI.join(host, object(id).key).to_s
195
+ URI.join(host, URI.encode(object(id).key)).to_s
195
196
  end
196
197
  end
197
198
 
198
199
  # Deletes all files from the storage (requires confirmation).
199
200
  def clear!(confirm = nil)
200
201
  raise Shrine::Confirm unless confirm == :confirm
201
- @bucket.object_versions(prefix: prefix).delete
202
+ bucket.object_versions(prefix: prefix).delete
202
203
  end
203
204
 
204
205
  # Returns a signature for direct uploads. Internally it calls
@@ -215,12 +216,12 @@ class Shrine
215
216
 
216
217
  # Returns the S3 object.
217
218
  def object(id)
218
- @bucket.object([*prefix, id].join("/"))
219
+ bucket.object([*prefix, id].join("/"))
219
220
  end
220
221
 
221
222
  # This is used to check whether an S3 file is copyable.
222
223
  def access_key_id
223
- @s3.client.config.credentials.credentials.access_key_id
224
+ s3.client.config.credentials.credentials.access_key_id
224
225
  end
225
226
 
226
227
  private
@@ -238,7 +239,7 @@ class Shrine
238
239
 
239
240
  # The file is copyable if it's on S3 and on the same Amazon account.
240
241
  def copyable?(io)
241
- io.respond_to?(:storage) &&
242
+ io.is_a?(UploadedFile) &&
242
243
  io.storage.is_a?(Storage::S3) &&
243
244
  io.storage.access_key_id == access_key_id
244
245
  end
@@ -5,7 +5,7 @@ class Shrine
5
5
 
6
6
  module VERSION
7
7
  MAJOR = 1
8
- MINOR = 3
8
+ MINOR = 4
9
9
  TINY = 0
10
10
  PRE = nil
11
11
 
data/lib/shrine.rb CHANGED
@@ -516,6 +516,7 @@ class Shrine
516
516
  # be called after saving.
517
517
  def finalize
518
518
  replace
519
+ remove_instance_variable("@old")
519
520
  _promote
520
521
  end
521
522
 
@@ -526,8 +527,8 @@ class Shrine
526
527
 
527
528
  # Uploads the cached file to store, and updates the record with the
528
529
  # stored file.
529
- def promote(cached_file)
530
- stored_file = store!(cached_file, phase: :store)
530
+ def promote(cached_file, phase: :store)
531
+ stored_file = store!(cached_file, phase: phase)
531
532
  result = swap(stored_file) or delete!(stored_file, phase: :stored)
532
533
  result
533
534
  end
@@ -537,7 +538,6 @@ class Shrine
537
538
  # don't get called for the current attachment anymore.
538
539
  def replace
539
540
  delete!(@old, phase: :replaced) if @old && !cache.uploaded?(@old)
540
- remove_instance_variable("@old")
541
541
  end
542
542
 
543
543
  # Deletes the attachment. Typically this should be called after
@@ -590,7 +590,7 @@ class Shrine
590
590
  # Calls #update, overriden in ORM plugins.
591
591
  def swap(uploaded_file)
592
592
  update(uploaded_file)
593
- uploaded_file
593
+ uploaded_file if get == uploaded_file
594
594
  end
595
595
 
596
596
  # Sets and saves the uploaded file.
data/shrine.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
 
19
19
  gem.add_dependency "down", ">= 2.0.1"
20
20
 
21
- gem.add_development_dependency "rake"
21
+ gem.add_development_dependency "rake", "~> 11.1"
22
22
  gem.add_development_dependency "minitest", "~> 5.8"
23
23
  gem.add_development_dependency "minitest-hooks", "~> 1.3.0"
24
24
  gem.add_development_dependency "mocha"
@@ -30,7 +30,6 @@ Gem::Specification.new do |gem|
30
30
  gem.add_development_dependency "mimemagic"
31
31
  gem.add_development_dependency "mime-types"
32
32
  gem.add_development_dependency "fastimage"
33
- gem.add_development_dependency "thread", "~> 0.2"
34
33
  gem.add_development_dependency "aws-sdk", "~> 2.1.30"
35
34
 
36
35
  unless RUBY_ENGINE == "jruby" || ENV["CI"]
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.3.0
4
+ version: 1.4.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-03-12 00:00:00.000000000 Z
11
+ date: 2016-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '11.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '11.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -178,20 +178,6 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
- - !ruby/object:Gem::Dependency
182
- name: thread
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - "~>"
186
- - !ruby/object:Gem::Version
187
- version: '0.2'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - "~>"
193
- - !ruby/object:Gem::Version
194
- version: '0.2'
195
181
  - !ruby/object:Gem::Dependency
196
182
  name: aws-sdk
197
183
  requirement: !ruby/object:Gem::Requirement
@@ -291,6 +277,8 @@ files:
291
277
  - lib/shrine/plugins/default_storage.rb
292
278
  - lib/shrine/plugins/default_url.rb
293
279
  - lib/shrine/plugins/default_url_options.rb
280
+ - lib/shrine/plugins/delete_promoted.rb
281
+ - lib/shrine/plugins/delete_raw.rb
294
282
  - lib/shrine/plugins/delete_uploaded.rb
295
283
  - lib/shrine/plugins/determine_mime_type.rb
296
284
  - lib/shrine/plugins/direct_upload.rb
@@ -314,6 +302,7 @@ files:
314
302
  - lib/shrine/plugins/remove_attachment.rb
315
303
  - lib/shrine/plugins/remove_invalid.rb
316
304
  - lib/shrine/plugins/restore_cached.rb
305
+ - lib/shrine/plugins/restore_cached_data.rb
317
306
  - lib/shrine/plugins/sequel.rb
318
307
  - lib/shrine/plugins/store_dimensions.rb
319
308
  - lib/shrine/plugins/upload_options.rb
@@ -349,3 +338,4 @@ signing_key:
349
338
  specification_version: 4
350
339
  summary: Toolkit for file uploads in Ruby
351
340
  test_files: []
341
+ has_rdoc: