mongoid-grid_fs 1.9.2 → 2.0.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 +8 -8
- data/Gemfile +5 -0
- data/README.md +17 -13
- data/Rakefile +168 -134
- data/config.rb +5 -0
- data/gemfiles/mongoid-3.0.gemfile +6 -0
- data/gemfiles/mongoid-3.1.gemfile +6 -0
- data/gemfiles/mongoid-4.0.gemfile +6 -0
- data/lib/mongoid-grid_fs.rb +61 -21
- data/mongoid-grid_fs.gemspec +12 -4
- data/script/shell +51 -0
- data/test/helper.rb +0 -2
- data/test/mongoid-grid_fs_test.rb +5 -3
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzI1NDRlODVhMWVmODUwZmNlNGQzYmQ3NmZmYWM3MzNlYWQ4ZWZjMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZGFiNDQ5YWIwMzZiN2JmZjllYzYyODQyODAyNTY0OTQ0YzE0MWNlMg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTYyNWQ0ZTEzZmM4ZTYwZWUyOTc4NWE4NGEyNzE1MDJiOTMzMTkzNDQxNTEz
|
10
|
+
OGMwMGNhYzQ5ZmQ0NTAxOThiY2FkYTZiZmY2YjZhYzFjMmEyMGQ5NGQwMWJk
|
11
|
+
NGI3YWEzZTEyMTA3OWFlZGM2OTJmOGJlYjk4YjZhOTZkZWE5Y2M=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YWUxMjcwMGRkY2EzYTI2Njk3MzgyYTRlNDg5MmJhMjVmNDRiNzllODQwNzlm
|
14
|
+
ZDI4ZmIwOWE0MmZhNjgzZDBiOGQ4YTZkODU2NWRlMDQwN2IwZDUyOThkNmJh
|
15
|
+
MDg2ZTZjNWIyN2E5MjA4MGM5MTc5NmZkY2IwZWQzZDZlMjk5NjI=
|
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -8,31 +8,36 @@ INSTALL
|
|
8
8
|
|
9
9
|
SYNOPSIS
|
10
10
|
--------
|
11
|
+
```ruby
|
12
|
+
require 'mongoid-grid_fs'
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
id = g.id
|
17
|
-
|
18
|
-
grid_fs.
|
19
|
-
|
14
|
+
grid_fs = Mongoid::GridFs
|
15
|
+
|
16
|
+
g = grid_fs.put(readable)
|
17
|
+
|
18
|
+
id = g.id
|
19
|
+
|
20
|
+
grid_fs.get(id)
|
21
|
+
|
22
|
+
grid_fs.delete(id)
|
23
|
+
```
|
20
24
|
|
21
25
|
DESCRIPTION
|
22
26
|
-----------
|
23
27
|
mongoid_grid_fs is a pure mongoid 3 / moped implementation of the mongodb
|
24
28
|
grid_fs specification
|
25
29
|
|
26
|
-
ref: http://
|
30
|
+
ref: http://docs.mongodb.org/manual/reference/gridfs/
|
27
31
|
|
28
32
|
it has the following features:
|
29
33
|
|
30
34
|
- implementation is on top of mongoid for portability. moped (the driver) is
|
31
|
-
barely used
|
35
|
+
barely used, so the library should be quite durable except in the face of
|
36
|
+
massive changes to mongoid itself.
|
32
37
|
|
33
38
|
- simple, REST-like api
|
34
39
|
|
35
|
-
- support for custom namespaces (fs.files vs. image.files)
|
40
|
+
- support for custom namespaces (fs.files vs. image.files, as per the spec)
|
36
41
|
|
37
42
|
- pathnames and io-like objects can be written to the grid
|
38
43
|
|
@@ -43,8 +48,7 @@ it has the following features:
|
|
43
48
|
- [] and []= methods which allow the grid to be used like a giant file
|
44
49
|
hash in the sky
|
45
50
|
|
46
|
-
- supprt for data_uris
|
47
|
-
|
51
|
+
- supprt for data_uris, like a html5 boss
|
48
52
|
````erb
|
49
53
|
|
50
54
|
<%= image_tag :src => file.data_uri %>
|
data/Rakefile
CHANGED
@@ -1,33 +1,22 @@
|
|
1
|
-
|
2
|
-
"
|
3
|
-
|
4
|
-
This.synopsis =
|
5
|
-
"a mongoid 3/moped compatible implementation of the grid_fs specification"
|
6
|
-
|
7
|
-
This.rubyforge_project = 'codeforpeople'
|
8
|
-
This.author = "Ara T. Howard"
|
9
|
-
This.email = "ara.t.howard@gmail.com"
|
10
|
-
This.homepage = "https://github.com/ahoward/#{ This.lib }"
|
11
|
-
|
12
|
-
This.setup!
|
13
|
-
|
14
|
-
|
1
|
+
task :license do
|
2
|
+
open('LICENSE', 'w'){|fd| fd.puts "Ruby"}
|
3
|
+
end
|
15
4
|
|
16
5
|
task :default do
|
17
6
|
puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
|
18
7
|
end
|
19
8
|
|
20
9
|
task :test do
|
21
|
-
|
10
|
+
run_tests!
|
22
11
|
end
|
23
12
|
|
24
13
|
namespace :test do
|
25
|
-
task(:unit){
|
26
|
-
task(:functional){
|
27
|
-
task(:integration){
|
14
|
+
task(:unit){ run_tests!(:unit) }
|
15
|
+
task(:functional){ run_tests!(:functional) }
|
16
|
+
task(:integration){ run_tests!(:integration) }
|
28
17
|
end
|
29
18
|
|
30
|
-
def
|
19
|
+
def run_tests!(which = nil)
|
31
20
|
which ||= '**'
|
32
21
|
test_dir = File.join(This.dir, "test")
|
33
22
|
test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
|
@@ -38,28 +27,29 @@ def This.run_tests!(which = nil)
|
|
38
27
|
|
39
28
|
test_rbs.each_with_index do |test_rb, index|
|
40
29
|
testno = index + 1
|
41
|
-
command = "#{
|
30
|
+
#command = "#{ This.ruby } -w -I ./lib -I ./test/lib #{ test_rb }"
|
31
|
+
command = "#{ This.ruby } -I ./lib -I ./test/lib #{ test_rb }"
|
42
32
|
|
43
33
|
puts
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
34
|
+
say(div, :color => :cyan, :bold => true)
|
35
|
+
say("@#{ testno } => ", :bold => true, :method => :print)
|
36
|
+
say(command, :color => :cyan, :bold => true)
|
37
|
+
say(line, :color => :cyan, :bold => true)
|
48
38
|
|
49
39
|
system(command)
|
50
40
|
|
51
|
-
|
41
|
+
say(line, :color => :cyan, :bold => true)
|
52
42
|
|
53
43
|
status = $?.exitstatus
|
54
44
|
|
55
45
|
if status.zero?
|
56
|
-
|
57
|
-
|
46
|
+
say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
|
47
|
+
say("SUCCESS", :color => :green, :bold => true)
|
58
48
|
else
|
59
|
-
|
60
|
-
|
49
|
+
say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
|
50
|
+
say("FAILURE", :color => :red, :bold => true)
|
61
51
|
end
|
62
|
-
|
52
|
+
say(line, :color => :cyan, :bold => true)
|
63
53
|
|
64
54
|
exit(status) unless status.zero?
|
65
55
|
end
|
@@ -68,10 +58,10 @@ end
|
|
68
58
|
|
69
59
|
task :gemspec do
|
70
60
|
ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
|
71
|
-
ignore_directories = ['pkg'
|
72
|
-
ignore_files = ['test/log'
|
61
|
+
ignore_directories = ['pkg']
|
62
|
+
ignore_files = ['test/log']
|
73
63
|
|
74
|
-
shiteless =
|
64
|
+
shiteless =
|
75
65
|
lambda do |list|
|
76
66
|
list.delete_if do |entry|
|
77
67
|
next unless test(?e, entry)
|
@@ -79,8 +69,9 @@ task :gemspec do
|
|
79
69
|
ignore_extensions.any?{|ext| ext === extension}
|
80
70
|
end
|
81
71
|
list.delete_if do |entry|
|
72
|
+
next unless test(?d, entry)
|
82
73
|
dirname = File.expand_path(entry)
|
83
|
-
ignore_directories.any?{|dir|
|
74
|
+
ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
|
84
75
|
end
|
85
76
|
list.delete_if do |entry|
|
86
77
|
next unless test(?f, entry)
|
@@ -95,10 +86,10 @@ task :gemspec do
|
|
95
86
|
files = shiteless[Dir::glob("**/**")]
|
96
87
|
executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
|
97
88
|
#has_rdoc = true #File.exist?('doc')
|
98
|
-
test_files =
|
99
|
-
summary =
|
100
|
-
description =
|
101
|
-
license
|
89
|
+
test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
|
90
|
+
summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
|
91
|
+
description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
|
92
|
+
license = object.respond_to?(:license) ? object.license : "Ruby"
|
102
93
|
|
103
94
|
if This.extensions.nil?
|
104
95
|
This.extensions = []
|
@@ -109,7 +100,6 @@ task :gemspec do
|
|
109
100
|
end
|
110
101
|
extensions = [extensions].flatten.compact
|
111
102
|
|
112
|
-
# TODO
|
113
103
|
if This.dependencies.nil?
|
114
104
|
dependencies = []
|
115
105
|
else
|
@@ -121,11 +111,15 @@ task :gemspec do
|
|
121
111
|
end
|
122
112
|
end
|
123
113
|
|
114
|
+
if license.nil? && test(?s, 'LICENSE')
|
115
|
+
license = IO.binread('LICENSE')
|
116
|
+
end
|
117
|
+
|
124
118
|
template =
|
125
119
|
if test(?e, 'gemspec.erb')
|
126
|
-
|
120
|
+
Template{ IO.read('gemspec.erb') }
|
127
121
|
else
|
128
|
-
|
122
|
+
Template {
|
129
123
|
<<-__
|
130
124
|
## <%= lib %>.gemspec
|
131
125
|
#
|
@@ -160,20 +154,20 @@ task :gemspec do
|
|
160
154
|
}
|
161
155
|
end
|
162
156
|
|
163
|
-
|
157
|
+
Fu.mkdir_p(This.pkgdir)
|
164
158
|
gemspec = "#{ lib }.gemspec"
|
165
159
|
open(gemspec, "w"){|fd| fd.puts(template)}
|
166
160
|
This.gemspec = gemspec
|
167
161
|
end
|
168
162
|
|
169
163
|
task :gem => [:clean, :gemspec] do
|
170
|
-
|
164
|
+
Fu.mkdir_p(This.pkgdir)
|
171
165
|
before = Dir['*.gem']
|
172
166
|
cmd = "gem build #{ This.gemspec }"
|
173
167
|
`#{ cmd }`
|
174
168
|
after = Dir['*.gem']
|
175
169
|
gem = ((after - before).first || after.first) or abort('no gem!')
|
176
|
-
|
170
|
+
Fu.mv(gem, This.pkgdir)
|
177
171
|
This.gem = File.join(This.pkgdir, File.basename(gem))
|
178
172
|
end
|
179
173
|
|
@@ -187,21 +181,21 @@ task :readme do
|
|
187
181
|
samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
|
188
182
|
|
189
183
|
cmd = "cat #{ sample }"
|
190
|
-
samples <<
|
191
|
-
samples <<
|
184
|
+
samples << Util.indent(prompt + cmd, 2) << "\n\n"
|
185
|
+
samples << Util.indent(`#{ cmd }`, 4) << "\n"
|
192
186
|
|
193
187
|
cmd = "ruby #{ sample }"
|
194
|
-
samples <<
|
188
|
+
samples << Util.indent(prompt + cmd, 2) << "\n\n"
|
195
189
|
|
196
190
|
cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
|
197
|
-
samples <<
|
191
|
+
samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
|
198
192
|
end
|
199
193
|
|
200
194
|
template =
|
201
|
-
if test(?e, '
|
202
|
-
|
195
|
+
if test(?e, 'README.erb')
|
196
|
+
Template{ IO.read('README.erb') }
|
203
197
|
else
|
204
|
-
|
198
|
+
Template {
|
205
199
|
<<-__
|
206
200
|
NAME
|
207
201
|
#{ lib }
|
@@ -222,7 +216,7 @@ end
|
|
222
216
|
|
223
217
|
|
224
218
|
task :clean do
|
225
|
-
Dir[File.join(This.pkgdir, '**/**')].each{|entry|
|
219
|
+
Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
|
226
220
|
end
|
227
221
|
|
228
222
|
|
@@ -237,11 +231,11 @@ task :release => [:clean, :gemspec, :gem] do
|
|
237
231
|
system(cmd)
|
238
232
|
abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
|
239
233
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
234
|
+
cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }"
|
235
|
+
puts cmd
|
236
|
+
puts
|
237
|
+
system(cmd)
|
238
|
+
abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
|
245
239
|
end
|
246
240
|
|
247
241
|
|
@@ -253,106 +247,151 @@ BEGIN {
|
|
253
247
|
#
|
254
248
|
$VERBOSE = nil
|
255
249
|
|
250
|
+
require 'ostruct'
|
256
251
|
require 'erb'
|
257
252
|
require 'fileutils'
|
258
253
|
require 'rbconfig'
|
259
254
|
require 'pp'
|
260
255
|
|
261
|
-
#
|
256
|
+
# fu shortcut
|
262
257
|
#
|
258
|
+
Fu = FileUtils
|
263
259
|
|
264
|
-
|
265
|
-
|
260
|
+
# pkg dir
|
261
|
+
#
|
262
|
+
Dir.chdir(File.dirname(__FILE__))
|
266
263
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
264
|
+
# config object
|
265
|
+
#
|
266
|
+
class Cfg < ::Hash
|
267
|
+
def method_missing(method, *args, &block)
|
268
|
+
method = method.to_s
|
269
|
+
case method
|
270
|
+
when /=$/
|
271
|
+
key = method.chomp('=')
|
272
|
+
value = args.shift
|
271
273
|
self[key] = value
|
274
|
+
when /\?$/
|
275
|
+
key = method.chomp('?')
|
276
|
+
self.key?(key)
|
277
|
+
when /\!$/
|
278
|
+
key = method.chomp('!')
|
279
|
+
self[key] = !!self[key]
|
272
280
|
else
|
273
|
-
key = method
|
274
|
-
if block
|
275
|
-
|
276
|
-
|
277
|
-
else
|
278
|
-
value = self[key]
|
279
|
-
|
280
|
-
if value.respond_to?(:call)
|
281
|
-
self[key] = value.call()
|
281
|
+
key = method
|
282
|
+
if args.empty? && block.nil?
|
283
|
+
if has_key?(key)
|
284
|
+
self[key]
|
282
285
|
else
|
283
|
-
|
286
|
+
nil
|
287
|
+
#raise IndexError, key
|
284
288
|
end
|
289
|
+
else
|
290
|
+
value =
|
291
|
+
case
|
292
|
+
when args.size > 0
|
293
|
+
args.shift
|
294
|
+
when block
|
295
|
+
block.call
|
296
|
+
end
|
297
|
+
self[key] = value
|
285
298
|
end
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
def inspect
|
290
|
-
expand!
|
291
|
-
PP.pp(self, '')
|
292
299
|
end
|
300
|
+
end
|
293
301
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
self[key] = value.call()
|
299
|
-
end
|
300
|
-
end
|
301
|
-
end
|
302
|
+
def eval(string)
|
303
|
+
instance_eval(string)
|
304
|
+
end
|
305
|
+
end
|
302
306
|
|
303
|
-
|
307
|
+
# cache a bunch of stuff about this rakefile/environment
|
308
|
+
#
|
309
|
+
This = Cfg.new
|
304
310
|
|
305
311
|
This.file = File.expand_path(__FILE__)
|
306
312
|
This.dir = File.dirname(This.file)
|
307
313
|
This.pkgdir = File.join(This.dir, 'pkg')
|
308
314
|
|
309
|
-
#
|
315
|
+
# load config iff present
|
310
316
|
#
|
311
|
-
This.
|
312
|
-
File.basename(Dir.pwd)
|
313
|
-
end
|
317
|
+
This.eval(IO.binread('config.rb')) if test(?s, 'config.rb')
|
314
318
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
319
|
+
# grok lib
|
320
|
+
#
|
321
|
+
unless This.lib?
|
322
|
+
lib = ENV['LIB']
|
323
|
+
unless lib
|
324
|
+
lib = File.basename(Dir.pwd)
|
320
325
|
end
|
326
|
+
This.lib = lib
|
321
327
|
end
|
322
328
|
|
323
|
-
|
324
|
-
|
329
|
+
# load lib
|
330
|
+
#
|
331
|
+
$LOAD_PATH.unshift('./lib')
|
332
|
+
Kernel.require(This.lib)
|
333
|
+
|
334
|
+
# grok the lib's object
|
335
|
+
#
|
336
|
+
unless This.object?
|
337
|
+
unless This.name?
|
338
|
+
This.name = File.basename(This.lib).split('_').each{|s| s.capitalize }.join('')
|
339
|
+
end
|
340
|
+
This.object = eval(This.name)
|
341
|
+
else
|
342
|
+
if This.object.is_a?(String)
|
343
|
+
This.object = eval(This.object)
|
344
|
+
unless This.name?
|
345
|
+
This.name = This.object.name
|
346
|
+
end
|
347
|
+
end
|
325
348
|
end
|
326
349
|
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
350
|
+
# grok version
|
351
|
+
#
|
352
|
+
unless This.version?
|
353
|
+
if This.object.respond_to?(:version)
|
354
|
+
This.version = This.object.send(:version)
|
332
355
|
end
|
333
356
|
end
|
357
|
+
abort 'no version' unless This.version?
|
334
358
|
|
335
|
-
|
336
|
-
|
359
|
+
# see if dependencies are exported by the module
|
360
|
+
#
|
361
|
+
if This.object.respond_to?(:dependencies)
|
362
|
+
This.dependencies = This.object.dependencies
|
363
|
+
else
|
364
|
+
This.dependencies = []
|
337
365
|
end
|
338
366
|
|
339
|
-
|
340
|
-
|
341
|
-
|
367
|
+
# set some reasonable defaults
|
368
|
+
#
|
369
|
+
{
|
370
|
+
|
371
|
+
:synopsis => "#{ This.name } kicks the ass",
|
372
|
+
:rubyforge_project => 'codeforpeople',
|
373
|
+
:author => "Ara T. Howard",
|
374
|
+
:email => "ara.t.howard@gmail.com",
|
375
|
+
:homepage => "https://github.com/ahoward/#{ This.lib }"
|
376
|
+
|
377
|
+
}.each do |key, val|
|
378
|
+
unless This.send("#{ key }?")
|
379
|
+
This.send("#{ key }=", val)
|
342
380
|
end
|
343
381
|
end
|
344
382
|
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
383
|
+
# discover full path to this ruby executable
|
384
|
+
#
|
385
|
+
c = Config::CONFIG
|
386
|
+
bindir = c["bindir"] || c['BINDIR']
|
387
|
+
ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
|
388
|
+
ruby_ext = c['EXEEXT'] || ''
|
389
|
+
ruby = File.join(bindir, (ruby_install_name + ruby_ext))
|
390
|
+
This.ruby = ruby
|
352
391
|
|
353
392
|
# some utils
|
354
393
|
#
|
355
|
-
|
394
|
+
module Util
|
356
395
|
def indent(s, n = 2)
|
357
396
|
s = unindent(s)
|
358
397
|
ws = ' ' * n
|
@@ -362,33 +401,27 @@ BEGIN {
|
|
362
401
|
def unindent(s)
|
363
402
|
indent = nil
|
364
403
|
s.each_line do |line|
|
365
|
-
|
366
|
-
|
367
|
-
end
|
368
|
-
indent ? s.gsub(%r/^#{ indent }/, "") : s
|
404
|
+
next if line =~ %r/^\s*$/
|
405
|
+
indent = line[%r/^\s*/] and break
|
369
406
|
end
|
370
|
-
|
407
|
+
indent ? s.gsub(%r/^#{ indent }/, "") : s
|
408
|
+
end
|
371
409
|
extend self
|
372
410
|
end
|
373
411
|
|
374
412
|
# template support
|
375
413
|
#
|
376
|
-
|
414
|
+
class Template
|
377
415
|
def initialize(&block)
|
378
416
|
@block = block
|
379
417
|
@template = block.call.to_s
|
380
418
|
end
|
381
|
-
|
382
419
|
def expand(b=nil)
|
383
|
-
ERB.new(
|
420
|
+
ERB.new(Util.unindent(@template)).result((b||@block).binding)
|
384
421
|
end
|
385
|
-
|
386
422
|
alias_method 'to_s', 'expand'
|
387
423
|
end
|
388
|
-
|
389
|
-
def This.template_for(*args, &block)
|
390
|
-
This.template.new(*args, &block)
|
391
|
-
end
|
424
|
+
def Template(*args, &block) Template.new(*args, &block) end
|
392
425
|
|
393
426
|
# colored console output support
|
394
427
|
#
|
@@ -404,6 +437,7 @@ BEGIN {
|
|
404
437
|
:blink => "\e[5m",
|
405
438
|
:reverse => "\e[7m",
|
406
439
|
:concealed => "\e[8m",
|
440
|
+
|
407
441
|
:black => "\e[30m",
|
408
442
|
:red => "\e[31m",
|
409
443
|
:green => "\e[32m",
|
@@ -412,6 +446,7 @@ BEGIN {
|
|
412
446
|
:magenta => "\e[35m",
|
413
447
|
:cyan => "\e[36m",
|
414
448
|
:white => "\e[37m",
|
449
|
+
|
415
450
|
:on_black => "\e[40m",
|
416
451
|
:on_red => "\e[41m",
|
417
452
|
:on_green => "\e[42m",
|
@@ -421,8 +456,7 @@ BEGIN {
|
|
421
456
|
:on_cyan => "\e[46m",
|
422
457
|
:on_white => "\e[47m"
|
423
458
|
}
|
424
|
-
|
425
|
-
def This.say(something, *args)
|
459
|
+
def say(phrase, *args)
|
426
460
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
427
461
|
options[:color] = args.shift.to_s.to_sym unless args.empty?
|
428
462
|
keys = options.keys
|
@@ -431,7 +465,7 @@ BEGIN {
|
|
431
465
|
color = options[:color]
|
432
466
|
bold = options.has_key?(:bold)
|
433
467
|
|
434
|
-
parts = [
|
468
|
+
parts = [phrase]
|
435
469
|
parts.unshift(This.ansi[color]) if color
|
436
470
|
parts.unshift(This.ansi[:bold]) if bold
|
437
471
|
parts.push(This.ansi[:clear]) if parts.size > 1
|
data/config.rb
ADDED
data/lib/mongoid-grid_fs.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
module Mongoid
|
4
4
|
class GridFS
|
5
|
-
const_set :Version, '
|
5
|
+
const_set :Version, '2.0.0'
|
6
6
|
|
7
7
|
class << GridFS
|
8
8
|
def version
|
@@ -12,7 +12,7 @@
|
|
12
12
|
def dependencies
|
13
13
|
{
|
14
14
|
'mongoid' => [ 'mongoid' , '>= 3.0', '< 5.0' ] ,
|
15
|
-
'mime/types' => [ 'mime-types' , '>= 1.
|
15
|
+
'mime/types' => [ 'mime-types' , '>= 1.0', '< 3.0'] ,
|
16
16
|
}
|
17
17
|
end
|
18
18
|
|
@@ -173,20 +173,29 @@
|
|
173
173
|
attributes[:uploadDate] = attributes.delete(:upload_date)
|
174
174
|
end
|
175
175
|
|
176
|
+
if attributes.has_key?(:meta_data)
|
177
|
+
attributes[:metadata] = attributes.delete(:meta_data)
|
178
|
+
end
|
179
|
+
|
180
|
+
if attributes.has_key?(:aliases)
|
181
|
+
attributes[:aliases] = Array(attributes.delete(:aliases)).flatten.compact.map{|a| "#{ a }"}
|
182
|
+
end
|
183
|
+
|
176
184
|
md5 = Digest::MD5.new
|
177
185
|
length = 0
|
178
186
|
chunkSize = file.chunkSize
|
179
187
|
n = 0
|
180
188
|
|
181
189
|
GridFS.reading(readable) do |io|
|
182
|
-
|
183
|
-
|
184
|
-
attributes[:filename] ||=
|
190
|
+
unless attributes.has_key?(:filename)
|
191
|
+
attributes[:filename] =
|
185
192
|
[file.id.to_s, GridFS.extract_basename(io)].join('/').squeeze('/')
|
193
|
+
end
|
186
194
|
|
187
|
-
|
188
|
-
attributes[:contentType]
|
189
|
-
GridFS.extract_content_type(filename) || file.contentType
|
195
|
+
unless attributes.has_key?(:contentType)
|
196
|
+
attributes[:contentType] =
|
197
|
+
GridFS.extract_content_type(attributes[:filename]) || file.contentType
|
198
|
+
end
|
190
199
|
|
191
200
|
GridFS.chunking(io, chunkSize) do |buf|
|
192
201
|
md5 << buf
|
@@ -198,7 +207,6 @@
|
|
198
207
|
chunk.save!
|
199
208
|
chunks.push(chunk)
|
200
209
|
end
|
201
|
-
|
202
210
|
end
|
203
211
|
|
204
212
|
attributes[:length] ||= length
|
@@ -246,12 +254,14 @@
|
|
246
254
|
end
|
247
255
|
|
248
256
|
def [](filename)
|
249
|
-
file_model.
|
257
|
+
file_model.
|
258
|
+
where(:filename => filename.to_s).
|
259
|
+
order_by(:uploadDate => :desc).
|
260
|
+
limit(1).
|
261
|
+
first
|
250
262
|
end
|
251
263
|
|
252
264
|
def []=(filename, readable)
|
253
|
-
file = self[filename]
|
254
|
-
file.destroy if file
|
255
265
|
put(readable, :filename => filename.to_s)
|
256
266
|
end
|
257
267
|
|
@@ -312,29 +322,51 @@
|
|
312
322
|
self.defaults.chunkSize = 4 * (mb = 2**20)
|
313
323
|
self.defaults.contentType = 'application/octet-stream'
|
314
324
|
|
315
|
-
field(:filename, :type => String)
|
316
|
-
field(:contentType, :type => String, :default => defaults.contentType)
|
317
|
-
|
318
325
|
field(:length, :type => Integer, :default => 0)
|
319
326
|
field(:chunkSize, :type => Integer, :default => defaults.chunkSize)
|
320
327
|
field(:uploadDate, :type => Time, :default => Time.now.utc)
|
321
328
|
field(:md5, :type => String, :default => Digest::MD5.hexdigest(''))
|
322
329
|
|
323
|
-
|
330
|
+
field(:filename, :type => String)
|
331
|
+
field(:contentType, :type => String, :default => defaults.contentType)
|
332
|
+
field(:aliases, :type => Array)
|
333
|
+
field(:metadata) rescue nil
|
334
|
+
|
335
|
+
required = %w( length chunkSize uploadDate md5 )
|
336
|
+
|
337
|
+
required.each do |f|
|
324
338
|
validates_presence_of(f)
|
325
339
|
end
|
326
|
-
validates_uniqueness_of(:filename)
|
327
340
|
|
328
|
-
|
341
|
+
index({:filename => 1})
|
342
|
+
index({:aliases => 1})
|
343
|
+
index({:uploadDate => 1})
|
344
|
+
index({:md5 => 1})
|
329
345
|
|
330
|
-
|
346
|
+
has_many(:chunks, :class_name => chunk_model_name, :inverse_of => :files, :dependent => :destroy, :order => [:n, :asc])
|
331
347
|
|
332
348
|
def path
|
333
349
|
filename
|
334
350
|
end
|
335
351
|
|
336
352
|
def basename
|
337
|
-
::File.basename(filename)
|
353
|
+
::File.basename(filename) if filename
|
354
|
+
end
|
355
|
+
|
356
|
+
def attachment_filename(*paths)
|
357
|
+
return basename if basename
|
358
|
+
|
359
|
+
if paths.empty?
|
360
|
+
paths.push('attachment')
|
361
|
+
paths.push(id.to_s)
|
362
|
+
paths.push(updateDate.iso8601)
|
363
|
+
end
|
364
|
+
|
365
|
+
path = paths.join('--')
|
366
|
+
base = ::File.basename(path).split('.', 2).first
|
367
|
+
ext = GridFS.extract_extension(contentType)
|
368
|
+
|
369
|
+
"#{ base }.#{ ext }"
|
338
370
|
end
|
339
371
|
|
340
372
|
def prefix
|
@@ -570,6 +602,14 @@
|
|
570
602
|
end
|
571
603
|
end
|
572
604
|
|
605
|
+
def GridFS.extract_extension(content_type)
|
606
|
+
list = MIME::Types[content_type.to_s]
|
607
|
+
type = list.first
|
608
|
+
if type
|
609
|
+
type.extensions.first
|
610
|
+
end
|
611
|
+
end
|
612
|
+
|
573
613
|
def GridFS.cleanname(pathname)
|
574
614
|
basename = ::File.basename(pathname.to_s)
|
575
615
|
CGI.unescape(basename).gsub(%r/[^0-9a-zA-Z_@)(~.-]/, '_').gsub(%r/_+/,'_')
|
@@ -592,7 +632,7 @@
|
|
592
632
|
options.to_options!
|
593
633
|
|
594
634
|
if options[:inline] == false or options[:attachment] == true
|
595
|
-
headers['Content-Disposition'] = "attachment; filename=#{ grid_fs_file.
|
635
|
+
headers['Content-Disposition'] = "attachment; filename=#{ grid_fs_file.attachment_filename }"
|
596
636
|
end
|
597
637
|
|
598
638
|
self.content_type = grid_fs_file.content_type
|
data/mongoid-grid_fs.gemspec
CHANGED
@@ -3,16 +3,22 @@
|
|
3
3
|
|
4
4
|
Gem::Specification::new do |spec|
|
5
5
|
spec.name = "mongoid-grid_fs"
|
6
|
-
spec.version = "
|
6
|
+
spec.version = "2.0.0"
|
7
7
|
spec.platform = Gem::Platform::RUBY
|
8
8
|
spec.summary = "mongoid-grid_fs"
|
9
|
-
spec.description = "
|
9
|
+
spec.description = "description: mongoid-grid_fs kicks the ass"
|
10
10
|
spec.license = "Ruby"
|
11
11
|
|
12
12
|
spec.files =
|
13
|
-
["
|
13
|
+
["Gemfile",
|
14
|
+
"LICENSE",
|
14
15
|
"README.md",
|
15
16
|
"Rakefile",
|
17
|
+
"config.rb",
|
18
|
+
"gemfiles",
|
19
|
+
"gemfiles/mongoid-3.0.gemfile",
|
20
|
+
"gemfiles/mongoid-3.1.gemfile",
|
21
|
+
"gemfiles/mongoid-4.0.gemfile",
|
16
22
|
"lib",
|
17
23
|
"lib/app",
|
18
24
|
"lib/app/models",
|
@@ -24,6 +30,8 @@ Gem::Specification::new do |spec|
|
|
24
30
|
"lib/app/models/mongoid/grid_fs/fs/file.rb",
|
25
31
|
"lib/mongoid-grid_fs.rb",
|
26
32
|
"mongoid-grid_fs.gemspec",
|
33
|
+
"script",
|
34
|
+
"script/shell",
|
27
35
|
"test",
|
28
36
|
"test/helper.rb",
|
29
37
|
"test/mongoid-grid_fs_test.rb",
|
@@ -38,7 +46,7 @@ Gem::Specification::new do |spec|
|
|
38
46
|
|
39
47
|
spec.add_dependency(*["mongoid", ">= 3.0", "< 5.0"])
|
40
48
|
|
41
|
-
spec.add_dependency(*["mime-types", ">= 1.
|
49
|
+
spec.add_dependency(*["mime-types", ">= 1.0", "< 3.0"])
|
42
50
|
|
43
51
|
|
44
52
|
spec.extensions.push(*[])
|
data/script/shell
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
gem 'rails', '>= 3', '< 4'
|
5
|
+
require 'rails'
|
6
|
+
require 'active_model'
|
7
|
+
|
8
|
+
#
|
9
|
+
require 'pry'
|
10
|
+
|
11
|
+
#
|
12
|
+
require_relative '../lib/mongoid-grid_fs.rb'
|
13
|
+
|
14
|
+
#
|
15
|
+
Mongoid.configure do |config|
|
16
|
+
config.connect_to('mongoid-grid_fs_test')
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
require 'irb'
|
21
|
+
|
22
|
+
$FUCKING_HACK = IRB.method(:load_modules)
|
23
|
+
|
24
|
+
def IRB.load_modules
|
25
|
+
$FUCKING_HACK.call()
|
26
|
+
|
27
|
+
prompt = 'mongoid_grid_fs'
|
28
|
+
|
29
|
+
IRB.conf[:PROMPT][:RO] = {
|
30
|
+
:PROMPT_I=>"#{ prompt }:%03n:%i> ",
|
31
|
+
:PROMPT_N=>"#{ prompt }:%03n:%i> ",
|
32
|
+
:PROMPT_S=>"#{ prompt }:%03n:%i%l ",
|
33
|
+
:PROMPT_C=>"#{ prompt }:%03n:%i* ",
|
34
|
+
:RETURN=>"=> %s\n"
|
35
|
+
}
|
36
|
+
|
37
|
+
IRB.conf[:PROMPT_MODE] = :RO
|
38
|
+
IRB.conf[:AUTO_INDENT] = true
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
module ::Kernel
|
43
|
+
def grid_fs
|
44
|
+
Mongoid::GridFS
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
ARGV.clear
|
50
|
+
|
51
|
+
::IRB.start
|
data/test/helper.rb
CHANGED
@@ -93,14 +93,16 @@ Testing Mongoid::GridFs do
|
|
93
93
|
|
94
94
|
before = GridFs::File.count
|
95
95
|
|
96
|
-
|
97
|
-
|
96
|
+
data = "#{ Time.now.to_f }-#{ rand }"
|
97
|
+
|
98
|
+
assert{ GridFs[path] = SIO.new(path, data) }
|
99
|
+
assert{ GridFs[path].data == data }
|
98
100
|
|
99
101
|
after = GridFs::File.count
|
100
102
|
|
101
103
|
created = after - before
|
102
104
|
|
103
|
-
assert{ created
|
105
|
+
assert{ created == 1 }
|
104
106
|
end
|
105
107
|
|
106
108
|
##
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-grid_fs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ara T. Howard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - ! '>='
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '1.
|
39
|
+
version: '1.0'
|
40
40
|
- - <
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '3.0'
|
@@ -46,24 +46,30 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - ! '>='
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '1.
|
49
|
+
version: '1.0'
|
50
50
|
- - <
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '3.0'
|
53
|
-
description:
|
53
|
+
description: ! 'description: mongoid-grid_fs kicks the ass'
|
54
54
|
email: ara.t.howard@gmail.com
|
55
55
|
executables: []
|
56
56
|
extensions: []
|
57
57
|
extra_rdoc_files: []
|
58
58
|
files:
|
59
|
+
- Gemfile
|
59
60
|
- LICENSE
|
60
61
|
- README.md
|
61
62
|
- Rakefile
|
63
|
+
- config.rb
|
64
|
+
- gemfiles/mongoid-3.0.gemfile
|
65
|
+
- gemfiles/mongoid-3.1.gemfile
|
66
|
+
- gemfiles/mongoid-4.0.gemfile
|
62
67
|
- lib/app/models/mongoid/grid_fs.rb
|
63
68
|
- lib/app/models/mongoid/grid_fs/fs/chunk.rb
|
64
69
|
- lib/app/models/mongoid/grid_fs/fs/file.rb
|
65
70
|
- lib/mongoid-grid_fs.rb
|
66
71
|
- mongoid-grid_fs.gemspec
|
72
|
+
- script/shell
|
67
73
|
- test/helper.rb
|
68
74
|
- test/mongoid-grid_fs_test.rb
|
69
75
|
- test/testing.rb
|