mongo_grid 0.2.9 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -12
- data/bin/resize +0 -0
- data/lib/mongo_grid/version.rb +1 -1
- data/lib/mongo_grid.rb +7 -3
- data/mongo_grid.gemspec +0 -8
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e282904f72ac6d5ae8d5151b448cbabbc1a2de1a3c6bc69331a94a0b52e41b7e
|
4
|
+
data.tar.gz: 88b72e432aa20e86f316051f3becf54f38f850b902eb432e5da744c8d0c5dd82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d59f07057c4b286a65107562e4fadfcd1ba68cc6dfaf2c0d87c01e43355da16375e2a5c52ca44db849aabdb7c068dd3acf3e1e46a71433886f4c45136ee5ee8
|
7
|
+
data.tar.gz: f72f9b9af7bf17ab134f04138a1006593407b594d72b39b8da31a490b0f08f18bb50370442e8b9b3c2603937d36d0e7042f7349c7223df5c456b085951f9531a
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# MongoGrid
|
2
2
|
|
3
|
-
|
3
|
+
MongoGrid simplify rails app file upload process.
|
4
|
+
It add some method to convience uploaded file to mongodb gridfs
|
4
5
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -27,24 +27,51 @@ MongoGrid.configure do |config|
|
|
27
27
|
config.db_url = "mongodb address" # '127.0.0.1:27017'
|
28
28
|
end
|
29
29
|
```
|
30
|
-
Then there are
|
30
|
+
Then there are several methods for use:
|
31
31
|
|
32
|
-
|
32
|
+
- grid : this method will return a mongo grid fs according previous configure
|
33
33
|
|
34
|
-
|
34
|
+
- remove(grid_id): this method will delete a file from mongo grid file system by grid_id
|
35
35
|
|
36
|
-
|
36
|
+
- uploadtogrid(tempfile,{}) : this method will save the upload file into gridfs. tempfile is the raw file input data submitted by a form , like params[:logo], this method will return a hash with keys filename,grid_id,content_type,file_length , and the {} keys is within {width, height} ,and only one of them , and if {} is empty? ,the images width default is 960.
|
37
|
+
- savetogrid(fpath,fname,content_type) : this method save file to gridfs directly from file system
|
37
38
|
|
38
|
-
|
39
|
+
## Little Tools
|
39
40
|
|
41
|
+
With this gem ,there is a little tools named resize, it is used to resize the upload image , type following command to see detailed usage.
|
42
|
+
```
|
43
|
+
resize -help
|
44
|
+
```
|
40
45
|
|
41
|
-
##
|
46
|
+
## Extensions
|
42
47
|
|
43
|
-
|
48
|
+
### Mongoid extensions
|
49
|
+
|
50
|
+
This gem also add four dynamic method in mongoid module.
|
51
|
+
```
|
52
|
+
- remove_logo
|
53
|
+
- remove_avatar
|
54
|
+
- remove_attach
|
55
|
+
- remove_embed
|
56
|
+
```
|
44
57
|
|
45
|
-
|
58
|
+
These methods can be used in module callback when you want to delete a document in mongodb
|
46
59
|
|
47
|
-
|
60
|
+
### Action Base extensions
|
48
61
|
|
49
|
-
|
62
|
+
There also three methods added in application controller :
|
63
|
+
```
|
64
|
+
- pageit
|
65
|
+
- attachit(model,attach = :attach,opts = {})
|
66
|
+
- need_role
|
67
|
+
```
|
50
68
|
|
69
|
+
- pageit used to page documentset in views
|
70
|
+
- attachit used to add uploaded file mongodb
|
71
|
+
- need_role used to add methods in controller before_action callback
|
72
|
+
```
|
73
|
+
need_role :teacher, :admin
|
74
|
+
# will add need_teacher, need_admin method
|
75
|
+
# can be used like
|
76
|
+
# before_action :need_teacher
|
77
|
+
```
|
data/bin/resize
ADDED
Binary file
|
data/lib/mongo_grid/version.rb
CHANGED
data/lib/mongo_grid.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'zbox'
|
2
1
|
require 'mongo_grid/version'
|
3
2
|
|
4
3
|
#Dir[File.join(File.dirname(__FILE__), 'mongo_grid', '*.rb')].each do |extension|
|
@@ -37,8 +36,13 @@ module ::MongoGrid
|
|
37
36
|
def uploadtogrid(upload,opts={})
|
38
37
|
filename=upload.original_filename
|
39
38
|
content_type=upload.content_type
|
40
|
-
|
41
|
-
|
39
|
+
if /jpg|jpeg|png/ =~ content_type
|
40
|
+
if opts[:width]
|
41
|
+
%x[resize -fixed -w #{opts[:width]} #{upload.tempfile.path}]
|
42
|
+
else
|
43
|
+
%x[resize -fixed #{upload.tempfile.path}]
|
44
|
+
end
|
45
|
+
|
42
46
|
end
|
43
47
|
data = File.open(upload.tempfile.path)
|
44
48
|
length=File.size(upload.tempfile.path)
|
data/mongo_grid.gemspec
CHANGED
@@ -14,14 +14,6 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = "https://rubygems.org/lajunta/mongo_grid"
|
15
15
|
spec.licenses = "MIT"
|
16
16
|
|
17
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
-
# delete this section to allow pushing this gem to any host.
|
19
|
-
#if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
-
#else
|
22
|
-
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
-
#end
|
24
|
-
|
25
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
18
|
spec.bindir = "exe"
|
27
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zxy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: file upload to mongodb
|
14
14
|
email:
|
@@ -22,6 +22,7 @@ files:
|
|
22
22
|
- README.md
|
23
23
|
- Rakefile
|
24
24
|
- bin/console
|
25
|
+
- bin/resize
|
25
26
|
- bin/setup
|
26
27
|
- lib/mongo_grid.rb
|
27
28
|
- lib/mongo_grid/action_base.rb
|
@@ -48,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
49
|
version: '0'
|
49
50
|
requirements: []
|
50
51
|
rubyforge_project:
|
51
|
-
rubygems_version: 2.7.
|
52
|
+
rubygems_version: 2.7.3
|
52
53
|
signing_key:
|
53
54
|
specification_version: 4
|
54
55
|
summary: a file upload gem for rails using mongodb
|