mongo_grid 0.2.2 → 0.2.3

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: f4669721ccc6ad3be4db769f9953eebb4eb01c02
4
- data.tar.gz: d250480b472bddec22383d2d61e04c4d35aa555e
3
+ metadata.gz: '019f529896d9bb02e5d9102af46d0bb8650f1a74'
4
+ data.tar.gz: 9b6297723832b03f6525854043b85bdcb20f01a5
5
5
  SHA512:
6
- metadata.gz: 92703b0e61cea355aa22d3cd026bc487b70aaf7c6dcb4584e1924bd96bb13a185b8375671dac16a2aac5ef01d80d9101cdd098d9082e1460d805cc63a03185a5
7
- data.tar.gz: 1c4af34157dd682320050962e404ba7e64385f498e2f3e0a01bf729fb832473301947cc71a84b20eab6a087cb6ce9bdb230de735ef7e4dc8aeca0cec843a6b76
6
+ metadata.gz: 4a5a51b81a6f8100fbc742b3c29824428735495a2c300078b324daf9d1b132c76c384b52445d7ec9683d4fc80de34c51c667a96aec823849cbc9a77a6881af4c
7
+ data.tar.gz: d91562e2ce969b8377c473c54b0dd09f35028d225eca9bd5cebd07a06fef1d30d7977acb8ef054c75868e8c0d9488e070386a13b0a48d84a2523bd395a2ab526
@@ -1,3 +1,3 @@
1
1
  module MongoGrid
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
data/lib/mongo_grid.rb CHANGED
@@ -19,6 +19,17 @@ module ::MongoGrid
19
19
  grid.delete(id)
20
20
  end
21
21
 
22
+ def fsize(length)
23
+ case length
24
+ when 0..(1024**2)
25
+ (length.to_f/1024.to_f).round(1).to_s+"K"
26
+ when (1024**2)...(1024**3)
27
+ (length.to_f/(1024**2).to_f).round(1).to_s+"M"
28
+ when (1024**3)...(1024**4)
29
+ (length.to_f/(1024**3).to_f).round(1).to_s+"G"
30
+ end
31
+ end
32
+
22
33
  def uploadtogrid(upload,opts={})
23
34
  filename=upload.original_filename
24
35
  content_type=upload.content_type
@@ -29,17 +40,21 @@ module ::MongoGrid
29
40
  length=File.size(upload.tempfile.path)
30
41
  gfile = ::Mongo::Grid::File.new(data,filename: filename, metadata: {content_type: content_type,length: length})
31
42
  gid = grid.insert_one(gfile)
32
- file_size =
33
- case length
34
- when 0..(1024**2)
35
- (length.to_f/1024.to_f).round(1).to_s+"K"
36
- when (1024**2)...(1024**3)
37
- (length.to_f/(1024**2).to_f).round(1).to_s+"M"
38
- when (1024**3)...(1024**4)
39
- (length.to_f/(1024**3).to_f).round(1).to_s+"G"
40
- end
43
+ file_size = fsize(length)
41
44
  hsh = {:grid_id=>gid.to_s,:filename=>filename,
42
45
  :content_type=>content_type,:file_size=>file_size}
43
46
  end
44
47
 
48
+ def savetogrid(fpath,fname="poster.jpg",content_type='image/jpeg')
49
+ data = File.open(fpath)
50
+ length=File.size(fpath)
51
+ gfile = ::Mongo::Grid::File.new(data,filename: fname, metadata: {content_type: content_type,length: length})
52
+ gid = grid.insert_one(gfile)
53
+ file_size = fsize(length)
54
+ hsh = {:grid_id=>gid.to_s,:filename=>fname,
55
+ :content_type=>content_type,:file_size=>file_size}
56
+
57
+ end
58
+
59
+
45
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_grid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - zxy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-12 00:00:00.000000000 Z
11
+ date: 2017-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler