mongo_grid 0.1.9 → 0.2.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 +4 -4
- metadata +4 -67
- data/.gitignore +0 -9
- data/Gemfile +0 -4
- data/README.md +0 -50
- data/Rakefile +0 -2
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/mongo_grid/version.rb +0 -3
- data/lib/mongo_grid.rb +0 -45
- data/mongo_grid.gemspec +0 -38
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 908fc3cc6cd66c28e95618d376b9115bfe698283
|
|
4
|
+
data.tar.gz: 1f707e3f870da80a0d476093571c761f19e24743
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c9d593c9c70968499acfb8beebf7b724cfdcb72a02716f25ba8a6260a956808325e2d216f99eea81527996dd9468fdce798de8662dad0d3ba6b76145095aaa42
|
|
7
|
+
data.tar.gz: 766fa171e093901a8a1c85e66eeef998df9e0ff167283a045a3b89175a0b102bff405ea53013a7fe30f233d6dedcf680eaf043127b65a961558cafc1a47f2406
|
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.2.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: 2017-04-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -98,76 +98,13 @@ dependencies:
|
|
|
98
98
|
- - ">="
|
|
99
99
|
- !ruby/object:Gem::Version
|
|
100
100
|
version: 2.1.0
|
|
101
|
-
- !ruby/object:Gem::Dependency
|
|
102
|
-
name: zbox
|
|
103
|
-
requirement: !ruby/object:Gem::Requirement
|
|
104
|
-
requirements:
|
|
105
|
-
- - "~>"
|
|
106
|
-
- !ruby/object:Gem::Version
|
|
107
|
-
version: 0.0.5
|
|
108
|
-
type: :runtime
|
|
109
|
-
prerelease: false
|
|
110
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
111
|
-
requirements:
|
|
112
|
-
- - "~>"
|
|
113
|
-
- !ruby/object:Gem::Version
|
|
114
|
-
version: 0.0.5
|
|
115
|
-
- !ruby/object:Gem::Dependency
|
|
116
|
-
name: bson
|
|
117
|
-
requirement: !ruby/object:Gem::Requirement
|
|
118
|
-
requirements:
|
|
119
|
-
- - "~>"
|
|
120
|
-
- !ruby/object:Gem::Version
|
|
121
|
-
version: '4.0'
|
|
122
|
-
- - ">="
|
|
123
|
-
- !ruby/object:Gem::Version
|
|
124
|
-
version: 4.0.0
|
|
125
|
-
type: :runtime
|
|
126
|
-
prerelease: false
|
|
127
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
128
|
-
requirements:
|
|
129
|
-
- - "~>"
|
|
130
|
-
- !ruby/object:Gem::Version
|
|
131
|
-
version: '4.0'
|
|
132
|
-
- - ">="
|
|
133
|
-
- !ruby/object:Gem::Version
|
|
134
|
-
version: 4.0.0
|
|
135
|
-
- !ruby/object:Gem::Dependency
|
|
136
|
-
name: mongo
|
|
137
|
-
requirement: !ruby/object:Gem::Requirement
|
|
138
|
-
requirements:
|
|
139
|
-
- - "~>"
|
|
140
|
-
- !ruby/object:Gem::Version
|
|
141
|
-
version: '2.1'
|
|
142
|
-
- - ">="
|
|
143
|
-
- !ruby/object:Gem::Version
|
|
144
|
-
version: 2.1.0
|
|
145
|
-
type: :runtime
|
|
146
|
-
prerelease: false
|
|
147
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
148
|
-
requirements:
|
|
149
|
-
- - "~>"
|
|
150
|
-
- !ruby/object:Gem::Version
|
|
151
|
-
version: '2.1'
|
|
152
|
-
- - ">="
|
|
153
|
-
- !ruby/object:Gem::Version
|
|
154
|
-
version: 2.1.0
|
|
155
101
|
description: file upload to mongodb
|
|
156
102
|
email:
|
|
157
103
|
- zxy@qq.com
|
|
158
104
|
executables: []
|
|
159
105
|
extensions: []
|
|
160
106
|
extra_rdoc_files: []
|
|
161
|
-
files:
|
|
162
|
-
- ".gitignore"
|
|
163
|
-
- Gemfile
|
|
164
|
-
- README.md
|
|
165
|
-
- Rakefile
|
|
166
|
-
- bin/console
|
|
167
|
-
- bin/setup
|
|
168
|
-
- lib/mongo_grid.rb
|
|
169
|
-
- lib/mongo_grid/version.rb
|
|
170
|
-
- mongo_grid.gemspec
|
|
107
|
+
files: []
|
|
171
108
|
homepage: https://rubygems.org/lajunta/mongo_grid
|
|
172
109
|
licenses:
|
|
173
110
|
- MIT
|
|
@@ -188,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
188
125
|
version: '0'
|
|
189
126
|
requirements: []
|
|
190
127
|
rubyforge_project:
|
|
191
|
-
rubygems_version: 2.6.
|
|
128
|
+
rubygems_version: 2.6.11
|
|
192
129
|
signing_key:
|
|
193
130
|
specification_version: 4
|
|
194
131
|
summary: a file upload gem for rails using mongodb
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/README.md
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
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
DELETED
data/bin/console
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
DELETED
data/lib/mongo_grid/version.rb
DELETED
data/lib/mongo_grid.rb
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
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
|
data/mongo_grid.gemspec
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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
|
-
spec.add_runtime_dependency "zbox", "~> 0.0.5"
|
|
36
|
-
spec.add_runtime_dependency "bson", "~> 4.0", '>= 4.0.0'
|
|
37
|
-
spec.add_runtime_dependency 'mongo', '~> 2.1', '>= 2.1.0'
|
|
38
|
-
end
|