mongo_grid 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 61c3aa3fe115ad5bf2060956f26dcbcfdcdd0006
4
+ data.tar.gz: 234814d29fcca14884058c2df213e48fd854a096
5
+ SHA512:
6
+ metadata.gz: 691339a64cefeb31683d8164fcd1e11d74b87dae7897ec7ce3771ffcebb5854432f1fb53512c6ade7a955e0365d9e3c22779824d44458a24265d7e53debac431
7
+ data.tar.gz: 0f7a2cb97da60f4d1cecf4299a86a3315e6358a8750477d0cf77e93a7054961c7823b9e8a3bebf587cf6fe1ab5ad5c7c4c4dc2c052d2a88eaec79422aa22bbda
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,39 @@
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
+
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
+ ## Development
31
+
32
+ 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.
33
+
34
+ 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).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mongo_grid.
39
+
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.1.0"
3
+ end
data/lib/mongo_grid.rb ADDED
@@ -0,0 +1,44 @@
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)
23
+ filename=upload.original_filename
24
+ content_type=upload.content_type
25
+ if content_type.include?("image")
26
+ ::Zbox::Qm.resize(upload.tempfile.path,:width=>900)
27
+ end
28
+ data = File.open(upload.tempfile.path)
29
+ gfile = ::Mongo::Grid::File.new(data,filename: filename, content_type: content_type)
30
+ gid = grid.insert_one(gfile)
31
+ grid_data=grid.find_one(_id: gid)
32
+ length=grid_data.chunk_size
33
+ file_size =
34
+ case length
35
+ when 0..1024**2
36
+ (length.to_f/1024.to_f).round(1).to_s+"K"
37
+ when 1024**2..1024*1024*15
38
+ (length.to_f/(1024*1024).to_f).round(1).to_s+"M"
39
+ end
40
+ hsh = {:grid_id=>gid.to_s,:filename=>filename,
41
+ :content_type=>content_type,:file_size=>file_size}
42
+ end
43
+
44
+ end
@@ -0,0 +1,34 @@
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 = ""
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ #if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ #else
21
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ #end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.11"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "zbox", "~> 0.0.4"
32
+ spec.add_development_dependency "bson", "~> 0 "
33
+ spec.add_development_dependency "mongo", "~> 0 "
34
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongo_grid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - zxy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: zbox
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.0.4
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: bson
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mongo
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: file upload to mongodb
84
+ email:
85
+ - zxy@qq.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - README.md
93
+ - Rakefile
94
+ - bin/console
95
+ - bin/setup
96
+ - lib/mongo_grid.rb
97
+ - lib/mongo_grid/version.rb
98
+ - mongo_grid.gemspec
99
+ homepage: ''
100
+ licenses: []
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.6.2
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: a file upload gem for rails using mongodb
122
+ test_files: []