shrine 1.4.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd828e546e0d244ed304996054f0bd01b790800d
4
- data.tar.gz: 46f44feb2075dd6d8001e990199acd99deae4223
3
+ metadata.gz: 8a38bb3cd054c90665a75f94355bdb28ae598591
4
+ data.tar.gz: eda94865fdc8f5fbcdff3464015a77e5d8bcfd45
5
5
  SHA512:
6
- metadata.gz: a2f0a33b73fb8a012b0e8036c6e1c62b2ad661ec38af4f16b72e80f3f7a39d9f42273232f5fd718f20330848c4db09b65f4f5fa28ca754bdaa31a56b32801fde
7
- data.tar.gz: c3e3791da4e71e600b0c973edc27a6f40145dffedbc8e0b2c835415d25990caed5d5f651f77091a4f12a7fdef26452a2ad53f20158486f0f486a1743470e5943
6
+ metadata.gz: 9160317e038ce1e401b716e49a812ef513ad3ff1cd9cc1a6663b71c3523f948db79c126e187615067e8af8f2436f495c5de3308a41cd27091ba3057dbc8c9e8a
7
+ data.tar.gz: da114a5953c31b3868f1bbb31e385b572919cb8ca854ecb1601b5c85a90336b7629628230a5b1c287c6f1b303ac17105b18ff6ad7660bf10fa33fd471f2c3d67
@@ -111,6 +111,9 @@ class Shrine
111
111
  end
112
112
  ```
113
113
 
114
+ You should also yield the total filesize as the second argument, so that
115
+ download_endpoint can set `Content-Length` before it starts streaming.
116
+
114
117
  ## Moving
115
118
 
116
119
  If your storage can move files, you can add 2 additional methods, and they will
@@ -25,8 +25,10 @@ class Shrine
25
25
  # `after_commit` callbacks won't get called, so in order to test uploading
26
26
  # you should first disable these transactions for those tests.
27
27
  #
28
- # If you want to put some parts of this lifecycle into a background job, see
29
- # the backgrounding plugin.
28
+ # If you want to put some parts of this lifecycle into a background job,
29
+ # see the backgrounding plugin. In that case you might want to use
30
+ # ActiveRecord's [optimistic locking] to eliminate the chance of race
31
+ # conditions.
30
32
  #
31
33
  # Additionally, any Shrine validation errors will be added to
32
34
  # ActiveRecord's errors upon validation. If you want to validate presence
@@ -36,6 +38,8 @@ class Shrine
36
38
  # include ImageUploader[:avatar]
37
39
  # validates_presence_of :avatar
38
40
  # end
41
+ #
42
+ # [optimistic locking]: http://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html
39
43
  module Activerecord
40
44
  module AttachmentMethods
41
45
  def included(model)
@@ -76,11 +80,13 @@ class Shrine
76
80
  # Updates the current attachment with the new one, unless the current
77
81
  # attachment has changed.
78
82
  def update(uploaded_file)
79
- record.class.where(record.class.primary_key => record.id)
80
- .where(:"#{name}_data" => record.send(:"#{name}_data"))
81
- .update_all(:"#{name}_data" => uploaded_file.to_json)
82
- record.reload
83
+ if record.send("#{name}_data") == record.reload.send("#{name}_data")
84
+ record.send("#{name}_data=", uploaded_file.to_json)
85
+ record.save(validate: false)
86
+ end
83
87
  rescue ::ActiveRecord::RecordNotFound
88
+ rescue ::ActiveRecord::StaleObjectError
89
+ retry
84
90
  end
85
91
  end
86
92
  end
@@ -3,9 +3,9 @@ require "roda"
3
3
  class Shrine
4
4
  module Plugins
5
5
  # The download_endpoint plugin provides a [Roda] endpoint for downloading
6
- # uploaded files from specified storages. This is useful when files from
7
- # your storages aren't accessible over URL (e.g. database storages) or if
8
- # you want to authenticate your downloads.
6
+ # uploaded files from specified storages. This can be useful when files
7
+ # from your storages aren't accessible over URL (e.g. database storages) or
8
+ # if you want to authenticate your downloads.
9
9
  #
10
10
  # plugin :download_endpoint, storages: [:store], prefix: "attachments"
11
11
  #
@@ -21,7 +21,7 @@ class Shrine
21
21
  # to the endpoint for specified storages, so it's not needed to change the
22
22
  # code:
23
23
  #
24
- # user.avatar_url #=> "/attachments/store/sdg0lsf8.jpg"
24
+ # user.avatar.url #=> "/attachments/store/sdg0lsf8.jpg"
25
25
  #
26
26
  # :storages
27
27
  # : An array of storage keys which the download endpoint should be used for.
@@ -1,5 +1,7 @@
1
1
  require "sequel"
2
2
 
3
+ Sequel::Model.plugin :instance_filters
4
+
3
5
  class Shrine
4
6
  module Plugins
5
7
  # The sequel plugin extends the "attachment" interface with support for
@@ -19,8 +21,8 @@ class Shrine
19
21
  # so that `after_commit` and `after_destroy_commit` callbacks get properly
20
22
  # called.
21
23
  #
22
- # If you want to put some parts of this lifecycle into a background job, see
23
- # the backgrounding plugin.
24
+ # If you want to put some parts of this lifecycle into a background job,
25
+ # see the backgrounding plugin.
24
26
  #
25
27
  # Additionally, any Shrine validation errors will added to Sequel's
26
28
  # errors upon validation. Note that if you want to validate presence of the
@@ -74,11 +76,10 @@ class Shrine
74
76
  # Updates the current attachment with the new one, unless the current
75
77
  # attachment has changed.
76
78
  def update(uploaded_file)
77
- record.this
78
- .where(:"#{name}_data" => record.send(:"#{name}_data"))
79
- .update(:"#{name}_data" => uploaded_file.to_json)
80
- record.reload
81
- rescue ::Sequel::Error
79
+ record.instance_filter(:"#{name}_data" => record.send("#{name}_data"))
80
+ record.send("#{name}_data=", uploaded_file.to_json)
81
+ record.save(validate: false)
82
+ rescue ::Sequel::NoExistingObject
82
83
  end
83
84
 
84
85
  # Support for Postgres JSON columns.
@@ -44,7 +44,7 @@ class Shrine
44
44
  # user.avatar[:medium].width #=> 500
45
45
  # user.avatar[:small].width #=> 300
46
46
  #
47
- # You probably want to load the `delete_uploaded` plugin to automatically
47
+ # You probably want to load the delete_raw plugin to automatically
48
48
  # delete processed files after they have been uploaded.
49
49
  #
50
50
  # The plugin also extends the `avatar_url` method to accept versions:
@@ -95,6 +95,7 @@ class Shrine
95
95
 
96
96
  if Array(streamed.first).size == 2
97
97
  error :stream, "yielded content length isn't a number" if !content_length.is_a?(Integer)
98
+ error :stream, "yielded chunks don't sum up to given content length" if content_length != chunks.inject("", :+).length
98
99
  end
99
100
  end
100
101
 
@@ -6,7 +6,7 @@ class Shrine
6
6
  module VERSION
7
7
  MAJOR = 1
8
8
  MINOR = 4
9
- TINY = 0
9
+ TINY = 1
10
10
  PRE = nil
11
11
 
12
12
  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: 1.4.0
4
+ version: 1.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-04-14 00:00:00.000000000 Z
11
+ date: 2016-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down