mongo_grid 0.2.9 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20e72df9bd1fee79336252093c3c959236f90f6c55be8d09c09e1ce520ac2226
4
- data.tar.gz: c3b75078ab8301ba206b7236bf2289ccf0ecc642d806e9d68614d99cbc393c89
3
+ metadata.gz: e282904f72ac6d5ae8d5151b448cbabbc1a2de1a3c6bc69331a94a0b52e41b7e
4
+ data.tar.gz: 88b72e432aa20e86f316051f3becf54f38f850b902eb432e5da744c8d0c5dd82
5
5
  SHA512:
6
- metadata.gz: 1f6fe24c57996cd1e18f8f3954f5462fee454a15698cbf29118fcb5347aebc2933ad51618044a639a8e04d3378238415544e4b418c05180787ebef0b2db0f753
7
- data.tar.gz: 1624f3aa6c926142603ba4e779f95584682e9fc14789f25b3173e0183d7b31f504ea47ea19acdf184fc6ad5d59089d5ac5f65f6d86f3c3c37a6ea991fa788f23
6
+ metadata.gz: 2d59f07057c4b286a65107562e4fadfcd1ba68cc6dfaf2c0d87c01e43355da16375e2a5c52ca44db849aabdb7c068dd3acf3e1e46a71433886f4c45136ee5ee8
7
+ data.tar.gz: f72f9b9af7bf17ab134f04138a1006593407b594d72b39b8da31a490b0f08f18bb50370442e8b9b3c2603937d36d0e7042f7349c7223df5c456b085951f9531a
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # MongoGrid
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mongo_grid`. To experiment with that code, run `bin/console` for an interactive prompt.
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 three main methods for use:
30
+ Then there are several methods for use:
31
31
 
32
- 1 grid : this method will return a mongo grid fs according previous configure
32
+ - grid : this method will return a mongo grid fs according previous configure
33
33
 
34
- 2 remove(grid_id): this method will delete a file from mongo grid file system by grid_id
34
+ - remove(grid_id): this method will delete a file from mongo grid file system by grid_id
35
35
 
36
- 3 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,percent} ,and only one of them , and if {} is empty? ,the images width default is 900.
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
- see Zbox::Qm.resize details
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
- ## Development
46
+ ## Extensions
42
47
 
43
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+ These methods can be used in module callback when you want to delete a document in mongodb
46
59
 
47
- ## Contributing
60
+ ### Action Base extensions
48
61
 
49
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mongo_grid.
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
@@ -1,3 +1,3 @@
1
1
  module MongoGrid
2
- VERSION = "0.2.9"
2
+ VERSION = "0.3.0"
3
3
  end
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
- if /jpg|jpeg|png/ =~ content_type
41
- ::Zbox::Qm.resize(upload.tempfile.path,opts)
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.2.9
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: 2018-11-11 00:00:00.000000000 Z
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.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