shrine 3.0.0 → 3.0.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.

@@ -0,0 +1,18 @@
1
+ ## Regressions
2
+
3
+ * Fixed `metadata_attributes` plugin raising an exception when the attachment
4
+ is removed (assigned to `nil`).
5
+
6
+ ## Improvements
7
+
8
+ * Simplified `UploadedFile#inspect` output:
9
+
10
+ ```rb
11
+ # before
12
+ uploaded_file.inspect
13
+ #=> #<Shrine::UploadedFile:0x00007fa4e4140d30 @id="cda84bbdab12b2bd41ea34590060a807", @storage_key=:memory, @metadata={"filename"=>nil, "size"=>0, "mime_type"=>nil}>
14
+
15
+ # after
16
+ uploaded_file.inspect
17
+ #=> #<Shrine::UploadedFile id="488b887dd792b4c82d3fc445140c5a38" storage=:memory metadata={"filename"=>nil, "size"=>0, "mime_type"=>nil}>
18
+ ```
@@ -4,7 +4,11 @@ title: Upgrading to Shrine 3.x
4
4
  ---
5
5
 
6
6
  This guide provides instructions for upgrading Shrine in your apps to version
7
- 3.x. If you're looking for a full list of changes, see the [3.0 release notes].
7
+ 3.x. If you're looking for a full list of changes, see the **[3.0 release
8
+ notes]**.
9
+
10
+ If you would like assistance with the upgrade, I'm available for consultation,
11
+ you can email me at <janko.marohnic@gmail.com>.
8
12
 
9
13
  ## Attacher
10
14
 
@@ -72,6 +76,20 @@ attacher.reload
72
76
  attacher.file #=> #<Shrine::UploadedFile ...>
73
77
  ```
74
78
 
79
+ ### Assigning
80
+
81
+ The `Attacher#assign` method now raises an exception when non-cached uploaded
82
+ file data is assigned:
83
+
84
+ ```rb
85
+ # Shrine 2.x
86
+ attacher.assign('{"id": "...", "storage": "store", "metadata": {...}}') # ignored
87
+
88
+ # Shrine 3.0
89
+ attacher.assign('{"id": "...", "storage": "store", "metadata": {...}}')
90
+ #~> Shrine::Error: expected cached file, got #<Shrine::UploadedFile storage=:store ...>
91
+ ```
92
+
75
93
  ### Validation
76
94
 
77
95
  The validation functionality has been extracted into the `validation` plugin.
@@ -352,7 +352,7 @@ class Shrine
352
352
  # reject files not uploaded to temporary storage, because otherwise
353
353
  # attackers could hijack other users' attachments
354
354
  unless cached?(uploaded_file)
355
- fail Shrine::Error, "expected cached file, got #{value.inspect}"
355
+ fail Shrine::Error, "expected cached file, got #{uploaded_file.inspect}"
356
356
  end
357
357
 
358
358
  uploaded_file
@@ -525,13 +525,13 @@ class Shrine
525
525
  # Converts data into a Hash of derivatives.
526
526
  #
527
527
  # Shrine.derivatives('{"thumb":{"id":"foo","storage":"store","metadata":{}}}')
528
- # #=> { thumb: #<Shrine::UploadedFile @id="foo" @storage_key="store" @metadata={}> }
528
+ # #=> { thumb: #<Shrine::UploadedFile id="foo" storage=:store metadata={}> }
529
529
  #
530
530
  # Shrine.derivatives({ "thumb" => { "id" => "foo", "storage" => "store", "metadata" => {} } })
531
- # #=> { thumb: #<Shrine::UploadedFile @id="foo" @storage_key="store" @metadata={}> }
531
+ # #=> { thumb: #<Shrine::UploadedFile id="foo" storage=:store metadata={}> }
532
532
  #
533
533
  # Shrine.derivatives({ thumb: { id: "foo", storage: "store", metadata: {} } })
534
- # #=> { thumb: #<Shrine::UploadedFile @id="foo" @storage_key="store" @metadata={}> }
534
+ # #=> { thumb: #<Shrine::UploadedFile id="foo" storage=:store metadata={}> }
535
535
  def derivatives(object)
536
536
  if object.is_a?(String)
537
537
  derivatives JSON.parse(object)
@@ -38,7 +38,7 @@ class Shrine
38
38
 
39
39
  next unless record.respond_to?(metadata_attribute)
40
40
 
41
- values[metadata_attribute] = file&.metadata[source.to_s]
41
+ values[metadata_attribute] = file && file.metadata[source.to_s]
42
42
  end
43
43
 
44
44
  values
@@ -249,6 +249,11 @@ class Shrine
249
249
  self.class.shrine_class
250
250
  end
251
251
 
252
+ # Returns simplified inspect output.
253
+ def inspect
254
+ "#<#{self.class.inspect} storage=#{storage_key.inspect} id=#{id.inspect} metadata=#{metadata.inspect}>"
255
+ end
256
+
252
257
  private
253
258
 
254
259
  # Returns an opened IO object for the uploaded file by calling `#open`
@@ -8,7 +8,7 @@ class Shrine
8
8
  module VERSION
9
9
  MAJOR = 3
10
10
  MINOR = 0
11
- TINY = 0
11
+ TINY = 1
12
12
  PRE = nil
13
13
 
14
14
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
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: 3.0.0
4
+ version: 3.0.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: 2019-10-14 00:00:00.000000000 Z
11
+ date: 2019-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down
@@ -466,6 +466,7 @@ files:
466
466
  - doc/release_notes/2.8.0.md
467
467
  - doc/release_notes/2.9.0.md
468
468
  - doc/release_notes/3.0.0.md
469
+ - doc/release_notes/3.0.1.md
469
470
  - doc/retrieving_uploads.md
470
471
  - doc/securing_uploads.md
471
472
  - doc/storage/file_system.md