shrine-gridfs 0.1.0 → 0.1.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: 49c11d81531933f8c3eaa0448f8d1216fd72fe6a
4
- data.tar.gz: 3227bf6c0438935cb4e014e2bb976dbc09612f98
3
+ metadata.gz: 70837530e37a9f4511e08a601f4d736e43255df1
4
+ data.tar.gz: a69505ea5b5871afc64a1cab36fb2c841ccdca75
5
5
  SHA512:
6
- metadata.gz: 83d330efac6ad0b2dcba7b49ff055f741f17882da41d8698efc610ead1ff9af43bec98876faf7a8ce0fdd95db34c06fc286c9a1686ab4363b4d6e5d3db9a6db5
7
- data.tar.gz: 47f8039bad05332b7ca9c36507a28245c6b6178a4dcb17bd73c2cd4c1d0d0a0b4b3475fbece5e91d9cac55b6801387ce007bbaf27ab12b952fe8255b7c30acdd
6
+ metadata.gz: 19a244bd4c63ca79e4e9ed1d670464c05067eb1572fec2f5c043e427b04493a88a369d88fef7a2ed4ed856eff3aa1abfb8f95eca57892d2b01f3b7f13e522ca7
7
+ data.tar.gz: a1f5aab1e3d9387500819d96bd87d25ff4a933dc6841283ffb46e1e70f4049937e77a0a85cd86d6731dd839d0de457bba9bc432775e638c2624d1600aac5b497
data/README.md CHANGED
@@ -26,6 +26,23 @@ option:
26
26
  Shrine::Storage::Gridfs.new(client: client, prefix: "foo")
27
27
  ```
28
28
 
29
+ ### URLs
30
+
31
+ You can generate URLs through which the GridFS files will be streamed with the
32
+ `download_endpoint` plugin:
33
+
34
+ ```rb
35
+ Shrine.plugin :download_endpoint, storages: [:store]
36
+ ```
37
+ ```rb
38
+ Rails.application.routes.draw do
39
+ mount Shrine::DownloadEndpoint => "/attachments"
40
+ end
41
+ ```
42
+ ```rb
43
+ user.avatar_url #=> "/attachments/store/9k30fks72j8.jpg"
44
+ ```
45
+
29
46
  ## Development
30
47
 
31
48
  You can run the tests with Rake:
@@ -1,3 +1,4 @@
1
+ require "shrine"
1
2
  require "mongo"
2
3
  require "stringio"
3
4
 
@@ -17,18 +18,22 @@ class Shrine
17
18
  filename = metadata["filename"] || id
18
19
  file = Mongo::Grid::File.new(io.read, filename: filename, metadata: metadata)
19
20
  result = bucket.insert_one(file)
20
- id.replace(result.to_s)
21
- io.rewind
21
+ id.replace(result.to_s + File.extname(id))
22
22
  end
23
23
 
24
24
  def download(id)
25
- filename = bucket.find(_id: bson_id(id)).first[:filename]
26
- tempfile = Tempfile.new(["shrine", File.extname(filename)], binmode: true)
25
+ tempfile = Tempfile.new(["shrine", File.extname(id)], binmode: true)
27
26
  bucket.download_to_stream(bson_id(id), tempfile)
28
27
  tempfile.open
29
28
  tempfile
30
29
  end
31
30
 
31
+ def stream(id)
32
+ bucket.open_download_stream(bson_id(id)) do |stream|
33
+ stream.each { |chunk| yield chunk }
34
+ end
35
+ end
36
+
32
37
  def open(id)
33
38
  download(id)
34
39
  end
@@ -65,7 +70,7 @@ class Shrine
65
70
  private
66
71
 
67
72
  def bson_id(id)
68
- BSON::ObjectId(id)
73
+ BSON::ObjectId(File.basename(id, ".*"))
69
74
  end
70
75
  end
71
76
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "shrine-gridfs"
3
- gem.version = "0.1.0"
3
+ gem.version = "0.1.1"
4
4
 
5
5
  gem.required_ruby_version = ">= 2.1"
6
6
 
@@ -13,10 +13,10 @@ Gem::Specification.new do |gem|
13
13
  gem.files = Dir["README.md", "LICENSE.txt", "lib/**/*.rb", "shrine-gridfs.gemspec"]
14
14
  gem.require_path = "lib"
15
15
 
16
+ gem.add_dependency "shrine", "~> 1.1"
16
17
  gem.add_dependency "mongo", ">= 2.2"
17
18
 
18
19
  gem.add_development_dependency "rake"
19
- gem.add_development_dependency "shrine"
20
20
  gem.add_development_dependency "minitest"
21
21
  gem.add_development_dependency "dotenv"
22
22
  end
metadata CHANGED
@@ -1,45 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-gridfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.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: 2015-12-18 00:00:00.000000000 Z
11
+ date: 2015-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: mongo
14
+ name: shrine
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.2'
19
+ version: '1.1'
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.2'
26
+ version: '1.1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: mongo
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
33
+ version: '2.2'
34
+ type: :runtime
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: '2.2'
41
41
  - !ruby/object:Gem::Dependency
42
- name: shrine
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="