shrine-gridfs 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 455d915875d2550fd43d92e4fc22b7afd7c798dc
4
- data.tar.gz: 57fed9ee75f80bd7b54872600a49697351db8b02
3
+ metadata.gz: e0c54bce081cf7e9ddfb91319ea7c7f2b87dce4d
4
+ data.tar.gz: 218dee27bac26e562c22ceaf8e1694dc221a90c2
5
5
  SHA512:
6
- metadata.gz: 364190c21872eab0f6c9ecd1cb0a0a01b4bfeef104f54c4f95bda1e903230f5260670565484b14e720aaa6f0d66c383ed01a55f63b39e4eefbbcb54b3d0429c5
7
- data.tar.gz: 790d48f5546a0aefa6619b8eaaa58d581d36300102e9014e958981c2d1f74679ea4e39385b3afcac27726acf088e04da0a5eda0ba8d0fe31a70b96d06e902869
6
+ metadata.gz: a4246aab41aa653b47c554990252302e94998e530390bffe9dacce31d2d7cfc9a5520babd5c0fb5bc4947bf400311920de9c9c4e4453c1f2cbc2471401871fb4
7
+ data.tar.gz: f61d44f87bbd1aa65da985d90964924a81a50d6c9e819113a645d353738c86abf851f0f217b80b066c86f81a5334d453f0c6cc682a3c4122e5c4cbbb54b6a7d4
@@ -1,5 +1,6 @@
1
1
  require "shrine"
2
2
  require "mongo"
3
+ require "down"
3
4
 
4
5
  require "stringio"
5
6
 
@@ -23,21 +24,18 @@ class Shrine
23
24
  end
24
25
 
25
26
  def download(id)
26
- tempfile = Tempfile.new(["shrine", File.extname(id)], binmode: true)
27
- bucket.download_to_stream(bson_id(id), tempfile)
28
- tempfile.open
29
- tempfile
27
+ Down.copy_to_tempfile(id, open(id))
30
28
  end
31
29
 
32
- def stream(id)
30
+ def open(id)
33
31
  content_length = bucket.find(_id: bson_id(id)).first["length"]
34
- bucket.open_download_stream(bson_id(id)) do |stream|
35
- stream.each { |chunk| yield chunk, content_length }
36
- end
37
- end
32
+ stream = bucket.open_download_stream(bson_id(id))
38
33
 
39
- def open(id)
40
- download(id)
34
+ Down::ChunkedIO.new(
35
+ size: content_length,
36
+ chunks: stream.enum_for(:each),
37
+ on_close: -> { stream.close },
38
+ )
41
39
  end
42
40
 
43
41
  def read(id)
@@ -68,6 +66,16 @@ class Shrine
68
66
  bucket.chunks_collection.find.delete_many
69
67
  end
70
68
 
69
+ def method_missing(name, *args)
70
+ if name == :stream
71
+ warn "Shrine::Storage::Gridfs#stream is deprecated over calling #each_chunk on result of Gridfs#open."
72
+ content_length = bucket.find(_id: bson_id(*args)).first["length"]
73
+ bucket.open_download_stream(bson_id(*args)) do |stream|
74
+ stream.each { |chunk| yield chunk, content_length }
75
+ end
76
+ end
77
+ end
78
+
71
79
  private
72
80
 
73
81
  def bson_id(id)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "shrine-gridfs"
3
- gem.version = "0.2.0"
3
+ gem.version = "0.2.1"
4
4
 
5
5
  gem.required_ruby_version = ">= 2.1"
6
6
 
@@ -15,6 +15,7 @@ Gem::Specification.new do |gem|
15
15
 
16
16
  gem.add_dependency "shrine", "~> 2.0"
17
17
  gem.add_dependency "mongo", ">= 2.2.2", "< 3"
18
+ gem.add_dependency "down", ">= 2.3.3"
18
19
 
19
20
  gem.add_development_dependency "rake"
20
21
  gem.add_development_dependency "minitest"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-gridfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.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-05-19 00:00:00.000000000 Z
11
+ date: 2016-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shrine
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '3'
47
+ - !ruby/object:Gem::Dependency
48
+ name: down
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 2.3.3
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.3.3
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: rake
49
63
  requirement: !ruby/object:Gem::Requirement