mongo_grid 0.2.1 → 0.2.2

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: 53b35c8f5943b9b1be309b4adca02ecb6c5cdd19
4
- data.tar.gz: 83cf46d8f52263557619fc35f71758278471fe3b
3
+ metadata.gz: f4669721ccc6ad3be4db769f9953eebb4eb01c02
4
+ data.tar.gz: d250480b472bddec22383d2d61e04c4d35aa555e
5
5
  SHA512:
6
- metadata.gz: 1e71f9135ea1885d81d4457ed51073f3c2d56794e9bf2893199bf39c4c42d33e867c5be94503133523150816677e31166ecf7aad25c270058d0ba706a0217efc
7
- data.tar.gz: d6e64e4e19b11a739693e89fcb43e8e71df6326ac81cc125969b2bca52267470e6e4f59b3b541769f21bb948bd4fa06bd9501ff5114668d68aca113f79a784ef
6
+ metadata.gz: 92703b0e61cea355aa22d3cd026bc487b70aaf7c6dcb4584e1924bd96bb13a185b8375671dac16a2aac5ef01d80d9101cdd098d9082e1460d805cc63a03185a5
7
+ data.tar.gz: 1c4af34157dd682320050962e404ba7e64385f498e2f3e0a01bf729fb832473301947cc71a84b20eab6a087cb6ce9bdb230de735ef7e4dc8aeca0cec843a6b76
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mongo_grid.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # MongoGrid
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.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mongo_grid'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mongo_grid
22
+
23
+ ## Usage
24
+ ```ruby
25
+ MongoGrid.configure do |config|
26
+ config.db_name = "your mongo db name" # 'app_development'
27
+ config.db_url = "mongodb address" # '127.0.0.1:27017'
28
+ end
29
+ ```
30
+ Then there are three main methods for use:
31
+
32
+ 1 grid : this method will return a mongo grid fs according previous configure
33
+
34
+ 2 remove(grid_id): this method will delete a file from mongo grid file system by grid_id
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.
37
+
38
+ see Zbox::Qm.resize details
39
+
40
+
41
+ ## Development
42
+
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.
44
+
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).
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mongo_grid.
50
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mongo_grid"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module MongoGrid
2
+ VERSION = "0.2.2"
3
+ end
data/lib/mongo_grid.rb ADDED
@@ -0,0 +1,45 @@
1
+ require "mongo_grid/version"
2
+ require 'zbox'
3
+
4
+ module ::MongoGrid
5
+ attr_accessor :db_name, :db_url
6
+ extend self
7
+
8
+ def configure
9
+ yield self
10
+ end
11
+
12
+ def grid
13
+ client = Mongo::Client.new([db_url], :database => db_name)
14
+ client.database.fs
15
+ end
16
+
17
+ def remove(gid)
18
+ id = BSON::ObjectId.from_string(gid)
19
+ grid.delete(id)
20
+ end
21
+
22
+ def uploadtogrid(upload,opts={})
23
+ filename=upload.original_filename
24
+ content_type=upload.content_type
25
+ if content_type.include?("image")
26
+ ::Zbox::Qm.resize(upload.tempfile.path,opts)
27
+ end
28
+ data = File.open(upload.tempfile.path)
29
+ length=File.size(upload.tempfile.path)
30
+ gfile = ::Mongo::Grid::File.new(data,filename: filename, metadata: {content_type: content_type,length: length})
31
+ 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
41
+ hsh = {:grid_id=>gid.to_s,:filename=>filename,
42
+ :content_type=>content_type,:file_size=>file_size}
43
+ end
44
+
45
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mongo_grid/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mongo_grid"
8
+ spec.version = MongoGrid::VERSION
9
+ spec.authors = ["zxy"]
10
+ spec.email = ["zxy@qq.com"]
11
+
12
+ spec.summary = %q{a file upload gem for rails using mongodb}
13
+ spec.description = %q{file upload to mongodb}
14
+ spec.homepage = "https://rubygems.org/lajunta/mongo_grid"
15
+ spec.licenses = "MIT"
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
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 11.2",'>=11.2.0'
32
+ spec.add_development_dependency "zbox", "~> 0.0.5"
33
+ spec.add_development_dependency "bson", "~>4.0",'>=4.0.0'
34
+ spec.add_development_dependency "mongo", "~> 2.1",'>=2.1.0'
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_grid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - zxy
@@ -104,7 +104,16 @@ email:
104
104
  executables: []
105
105
  extensions: []
106
106
  extra_rdoc_files: []
107
- files: []
107
+ files:
108
+ - ".gitignore"
109
+ - Gemfile
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/mongo_grid.rb
115
+ - lib/mongo_grid/version.rb
116
+ - mongo_grid.gemspec
108
117
  homepage: https://rubygems.org/lajunta/mongo_grid
109
118
  licenses:
110
119
  - MIT