gnuside-mongoid-grid_fs 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f6ac9976027c6d77344dd5e0c6cfd8d52e4a8caa
4
+ data.tar.gz: f05d8a3895e2f4b883dd11ebcb0c978acd583bc7
5
+ SHA512:
6
+ metadata.gz: 21b9dd63a39cf9f6aa9a96147c83ac2dd0b8b05b29529b3d3d20ca849cd4ce5bdc9c0ce18bfbbc53d7df8cebadc5eb0c9f4be6e515b6b0cf1c4b4ed3422a0aa6
7
+ data.tar.gz: 08cc84cda98067fbcc1c5233befbdd2fd5b1e78897cbd9bda9d6e603ee6ad80ce10d22dc40412203e9b7fe3dbb53a83ddad870ba88ae465b046fe72f92741317
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ NAME
2
+ ----
3
+ mongoid-grid_fs
4
+
5
+ INSTALL
6
+ -------
7
+ gem install mongoid-grid_fs
8
+
9
+ SYNOPSIS
10
+ --------
11
+
12
+ ````ruby
13
+ require 'mongoid-grid_fs'
14
+ grid_fs = Mongoid::GridFs
15
+ g = grid_fs.put(readable)
16
+ id = g.id
17
+ grid_fs.get(id)
18
+ grid_fs.delete(id)
19
+ ````
20
+
21
+ DESCRIPTION
22
+ -----------
23
+ mongoid_grid_fs is a pure mongoid 3 / moped implementation of the mongodb
24
+ grid_fs specification
25
+
26
+ ref: http://www.mongodb.org/display/DOCS/GridFS+Specification
27
+
28
+ it has the following features:
29
+
30
+ - implementation is on top of mongoid for portability. moped (the driver) is
31
+ barely used
32
+
33
+ - simple, REST-like api
34
+
35
+ - support for custom namespaces (fs.files vs. image.files)
36
+
37
+ - pathnames and io-like objects can be written to the grid
38
+
39
+ - auto-unique pathnames are generated (by default) to avoid collisions using #put
40
+
41
+ 'path/info/a.rb' -> '$object_id/a.rb'
42
+
43
+ - [] and []= methods which allow the grid to be used like a giant file
44
+ hash in the sky
45
+
46
+ - supprt for data_uris
47
+
48
+ ````erb
49
+
50
+ <%= image_tag :src => file.data_uri %>
51
+
52
+ ````
data/Rakefile ADDED
@@ -0,0 +1,445 @@
1
+ This.name =
2
+ "Mongoid::GridFs"
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
+
15
+
16
+ task :default do
17
+ puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
18
+ end
19
+
20
+ task :test do
21
+ This.run_tests!
22
+ end
23
+
24
+ namespace :test do
25
+ task(:unit){ This.run_tests!(:unit) }
26
+ task(:functional){ This.run_tests!(:functional) }
27
+ task(:integration){ This.run_tests!(:integration) }
28
+ end
29
+
30
+ def This.run_tests!(which = nil)
31
+ which ||= '**'
32
+ test_dir = File.join(This.dir, "test")
33
+ test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
34
+ test_rbs = Dir.glob(test_glob).sort
35
+
36
+ div = ('=' * 119)
37
+ line = ('-' * 119)
38
+
39
+ test_rbs.each_with_index do |test_rb, index|
40
+ testno = index + 1
41
+ command = "#{ File.basename(This.ruby) } -I ./lib -I ./test/lib #{ test_rb }"
42
+
43
+ puts
44
+ This.say(div, :color => :cyan, :bold => true)
45
+ This.say("@#{ testno } => ", :bold => true, :method => :print)
46
+ This.say(command, :color => :cyan, :bold => true)
47
+ This.say(line, :color => :cyan, :bold => true)
48
+
49
+ system(command)
50
+
51
+ This.say(line, :color => :cyan, :bold => true)
52
+
53
+ status = $?.exitstatus
54
+
55
+ if status.zero?
56
+ This.say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
57
+ This.say("SUCCESS", :color => :green, :bold => true)
58
+ else
59
+ This.say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
60
+ This.say("FAILURE", :color => :red, :bold => true)
61
+ end
62
+ This.say(line, :color => :cyan, :bold => true)
63
+
64
+ exit(status) unless status.zero?
65
+ end
66
+ end
67
+
68
+
69
+ task :gemspec do
70
+ ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
71
+ ignore_directories = ['pkg', 'db', 'vendor', 'gemfiles']
72
+ ignore_files = ['test/log', 'test/db.yml', 'a.rb', 'b.rb'] + Dir['Gemfile*'] + %w'db'
73
+
74
+ shiteless =
75
+ lambda do |list|
76
+ list.delete_if do |entry|
77
+ next unless test(?e, entry)
78
+ extension = File.basename(entry).split(%r/[.]/).last
79
+ ignore_extensions.any?{|ext| ext === extension}
80
+ end
81
+ list.delete_if do |entry|
82
+ dirname = File.expand_path(entry)
83
+ ignore_directories.any?{|dir| dirname.include?(File.expand_path(dir)) }
84
+ end
85
+ list.delete_if do |entry|
86
+ next unless test(?f, entry)
87
+ filename = File.expand_path(entry)
88
+ ignore_files.any?{|file| File.expand_path(file) == filename}
89
+ end
90
+ end
91
+
92
+ lib = This.lib
93
+ object = This.object
94
+ version = This.version
95
+ files = shiteless[Dir::glob("**/**")]
96
+ executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
97
+ #has_rdoc = true #File.exist?('doc')
98
+ test_files = test(?e, "test/#{ lib }.rb") ? "test/#{ lib }.rb" : nil
99
+ summary = This.summary || This.synopsis || "#{ lib } kicks the ass"
100
+ description = This.description || summary
101
+
102
+ if This.extensions.nil?
103
+ This.extensions = []
104
+ extensions = This.extensions
105
+ %w( Makefile configure extconf.rb ).each do |ext|
106
+ extensions << ext if File.exists?(ext)
107
+ end
108
+ end
109
+ extensions = [extensions].flatten.compact
110
+
111
+ # TODO
112
+ if This.dependencies.nil?
113
+ dependencies = []
114
+ else
115
+ case This.dependencies
116
+ when Hash
117
+ dependencies = This.dependencies.values
118
+ when Array
119
+ dependencies = This.dependencies
120
+ end
121
+ end
122
+
123
+ template =
124
+ if test(?e, 'gemspec.erb')
125
+ This.template_for{ IO.read('gemspec.erb') }
126
+ else
127
+ This.template_for {
128
+ <<-__
129
+ ## <%= lib %>.gemspec
130
+ #
131
+
132
+ Gem::Specification::new do |spec|
133
+ spec.name = <%= lib.inspect %>
134
+ spec.version = <%= version.inspect %>
135
+ spec.platform = Gem::Platform::RUBY
136
+ spec.summary = <%= lib.inspect %>
137
+ spec.description = <%= description.inspect %>
138
+
139
+ spec.files =\n<%= files.sort.pretty_inspect %>
140
+ spec.executables = <%= executables.inspect %>
141
+
142
+ spec.require_path = "lib"
143
+
144
+ spec.test_files = <%= test_files.inspect %>
145
+
146
+ <% dependencies.each do |lib_version| %>
147
+ spec.add_dependency(*<%= Array(lib_version).flatten.inspect %>)
148
+ <% end %>
149
+
150
+ spec.extensions.push(*<%= extensions.inspect %>)
151
+
152
+ spec.rubyforge_project = <%= This.rubyforge_project.inspect %>
153
+ spec.author = <%= This.author.inspect %>
154
+ spec.email = <%= This.email.inspect %>
155
+ spec.homepage = <%= This.homepage.inspect %>
156
+ end
157
+ __
158
+ }
159
+ end
160
+
161
+ FileUtils.mkdir_p(This.pkgdir)
162
+ gemspec = "#{ lib }.gemspec"
163
+ open(gemspec, "w"){|fd| fd.puts(template)}
164
+ This.gemspec = gemspec
165
+ end
166
+
167
+ task :gem => [:clean, :gemspec] do
168
+ FileUtils.mkdir_p(This.pkgdir)
169
+ before = Dir['*.gem']
170
+ cmd = "gem build #{ This.gemspec }"
171
+ `#{ cmd }`
172
+ after = Dir['*.gem']
173
+ gem = ((after - before).first || after.first) or abort('no gem!')
174
+ FileUtils.mv(gem, This.pkgdir)
175
+ This.gem = File.join(This.pkgdir, File.basename(gem))
176
+ end
177
+
178
+ task :readme do
179
+ samples = ''
180
+ prompt = '~ > '
181
+ lib = This.lib
182
+ version = This.version
183
+
184
+ Dir['sample*/*'].sort.each do |sample|
185
+ samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
186
+
187
+ cmd = "cat #{ sample }"
188
+ samples << This.util.indent(prompt + cmd, 2) << "\n\n"
189
+ samples << This.util.indent(`#{ cmd }`, 4) << "\n"
190
+
191
+ cmd = "ruby #{ sample }"
192
+ samples << This.util.indent(prompt + cmd, 2) << "\n\n"
193
+
194
+ cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
195
+ samples << This.util.indent(`#{ cmd } 2>&1`, 4) << "\n"
196
+ end
197
+
198
+ template =
199
+ if test(?e, 'readme.erb')
200
+ This.template_for{ IO.read('readme.erb') }
201
+ else
202
+ This.template_for {
203
+ <<-__
204
+ NAME
205
+ #{ lib }
206
+
207
+ DESCRIPTION
208
+
209
+ INSTALL
210
+ gem install #{ lib }
211
+
212
+ SAMPLES
213
+ #{ samples }
214
+ __
215
+ }
216
+ end
217
+
218
+ open("README", "w"){|fd| fd.puts template}
219
+ end
220
+
221
+
222
+ task :clean do
223
+ Dir[File.join(This.pkgdir, '**/**')].each{|entry| FileUtils.rm_rf(entry)}
224
+ end
225
+
226
+
227
+ task :release => [:clean, :gemspec, :gem] do
228
+ gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
229
+ raise "which one? : #{ gems.inspect }" if gems.size > 1
230
+ raise "no gems?" if gems.size < 1
231
+
232
+ cmd = "gem push #{ This.gem }"
233
+ puts cmd
234
+ puts
235
+ system(cmd)
236
+ abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
237
+
238
+ #cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }"
239
+ #puts cmd
240
+ #puts
241
+ #system(cmd)
242
+ #abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
243
+ end
244
+
245
+
246
+
247
+
248
+
249
+ BEGIN {
250
+ # support for this rakefile
251
+ #
252
+ $VERBOSE = nil
253
+
254
+ require 'erb'
255
+ require 'fileutils'
256
+ require 'rbconfig'
257
+ require 'pp'
258
+
259
+ # cache a bunch of stuff about this rakefile/environment
260
+ #
261
+
262
+ This =
263
+ Class.new(Hash) do
264
+
265
+ def method_missing(method, *args, &block)
266
+ if method.to_s =~ /=/
267
+ key = method.to_s.chomp('=')
268
+ value = block ? block : args.shift
269
+ self[key] = value
270
+ else
271
+ key = method.to_s
272
+ if block
273
+ value = block
274
+ self[key] = value
275
+ else
276
+ value = self[key]
277
+
278
+ if value.respond_to?(:call)
279
+ self[key] = value.call()
280
+ else
281
+ value
282
+ end
283
+ end
284
+ end
285
+ end
286
+
287
+ def inspect
288
+ expand!
289
+ PP.pp(self, '')
290
+ end
291
+
292
+ def expand!
293
+ keys.each do |key|
294
+ value = self[key]
295
+ if value.respond_to?(:call)
296
+ self[key] = value.call()
297
+ end
298
+ end
299
+ end
300
+
301
+ end.new()
302
+
303
+ This.file = File.expand_path(__FILE__)
304
+ This.dir = File.dirname(This.file)
305
+ This.pkgdir = File.join(This.dir, 'pkg')
306
+
307
+ # defaults
308
+ #
309
+ This.lib do
310
+ File.basename(Dir.pwd)
311
+ end
312
+
313
+ def This.setup!
314
+ begin
315
+ require "./lib/#{ This.lib }"
316
+ rescue LoadError
317
+ abort("could not load #{ This.lib }")
318
+ end
319
+ end
320
+
321
+ This.name do
322
+ This.name = This.lib.capitalize
323
+ end
324
+
325
+ This.object do
326
+ begin
327
+ This.object = eval(This.name)
328
+ rescue Object
329
+ abort("could not determine object from #{ This.name }")
330
+ end
331
+ end
332
+
333
+ This.version do
334
+ This.object.send(:version)
335
+ end
336
+
337
+ This.dependencies do
338
+ if This.object.respond_to?(:dependencies)
339
+ This.object.dependencies
340
+ end
341
+ end
342
+
343
+ This.ruby do
344
+ c = Config::CONFIG
345
+ bindir = c["bindir"] || c['BINDIR']
346
+ ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
347
+ ruby_ext = c['EXEEXT'] || ''
348
+ File.join(bindir, (ruby_install_name + ruby_ext))
349
+ end
350
+
351
+ # some utils
352
+ #
353
+ This.util = Module.new do
354
+ def indent(s, n = 2)
355
+ s = unindent(s)
356
+ ws = ' ' * n
357
+ s.gsub(%r/^/, ws)
358
+ end
359
+
360
+ def unindent(s)
361
+ indent = nil
362
+ s.each_line do |line|
363
+ next if line =~ %r/^\s*$/
364
+ indent = line[%r/^\s*/] and break
365
+ end
366
+ indent ? s.gsub(%r/^#{ indent }/, "") : s
367
+ end
368
+
369
+ extend self
370
+ end
371
+
372
+ # template support
373
+ #
374
+ This.template = Class.new do
375
+ def initialize(&block)
376
+ @block = block
377
+ @template = block.call.to_s
378
+ end
379
+
380
+ def expand(b=nil)
381
+ ERB.new(This.util.unindent(@template)).result((b||@block).binding)
382
+ end
383
+
384
+ alias_method 'to_s', 'expand'
385
+ end
386
+
387
+ def This.template_for(*args, &block)
388
+ This.template.new(*args, &block)
389
+ end
390
+
391
+ # colored console output support
392
+ #
393
+ This.ansi = {
394
+ :clear => "\e[0m",
395
+ :reset => "\e[0m",
396
+ :erase_line => "\e[K",
397
+ :erase_char => "\e[P",
398
+ :bold => "\e[1m",
399
+ :dark => "\e[2m",
400
+ :underline => "\e[4m",
401
+ :underscore => "\e[4m",
402
+ :blink => "\e[5m",
403
+ :reverse => "\e[7m",
404
+ :concealed => "\e[8m",
405
+ :black => "\e[30m",
406
+ :red => "\e[31m",
407
+ :green => "\e[32m",
408
+ :yellow => "\e[33m",
409
+ :blue => "\e[34m",
410
+ :magenta => "\e[35m",
411
+ :cyan => "\e[36m",
412
+ :white => "\e[37m",
413
+ :on_black => "\e[40m",
414
+ :on_red => "\e[41m",
415
+ :on_green => "\e[42m",
416
+ :on_yellow => "\e[43m",
417
+ :on_blue => "\e[44m",
418
+ :on_magenta => "\e[45m",
419
+ :on_cyan => "\e[46m",
420
+ :on_white => "\e[47m"
421
+ }
422
+
423
+ def This.say(something, *args)
424
+ options = args.last.is_a?(Hash) ? args.pop : {}
425
+ options[:color] = args.shift.to_s.to_sym unless args.empty?
426
+ keys = options.keys
427
+ keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
428
+
429
+ color = options[:color]
430
+ bold = options.has_key?(:bold)
431
+
432
+ parts = [something]
433
+ parts.unshift(This.ansi[color]) if color
434
+ parts.unshift(This.ansi[:bold]) if bold
435
+ parts.push(This.ansi[:clear]) if parts.size > 1
436
+
437
+ method = options[:method] || :puts
438
+
439
+ Kernel.send(method, parts.join)
440
+ end
441
+
442
+ # always run out of the project dir
443
+ #
444
+ Dir.chdir(This.dir)
445
+ }
@@ -0,0 +1,53 @@
1
+ ## mongoid-grid_fs.gemspec
2
+ #
3
+ lib = File.expand_path('../lib/', __FILE__)
4
+ $:.unshift lib unless $:.include?(lib)
5
+
6
+ require 'mongoid-grid_fs/version'
7
+
8
+ Gem::Specification::new do |spec|
9
+ spec.name = "gnuside-mongoid-grid_fs"
10
+ spec.version = Mongoid::GridFS::VERSION
11
+ spec.platform = Gem::Platform::RUBY
12
+ spec.summary = "mongoid-grid_fs"
13
+ spec.description = "a mongoid 3/moped compatible implementation of the grid_fs specification"
14
+ spec.license = "Ruby"
15
+
16
+ spec.files =
17
+ ["README.md",
18
+ "Rakefile",
19
+ "lib",
20
+ "lib/app",
21
+ "lib/app/models",
22
+ "lib/app/models/mongoid",
23
+ "lib/app/models/mongoid/grid_fs",
24
+ "lib/app/models/mongoid/grid_fs.rb",
25
+ "lib/app/models/mongoid/grid_fs/fs",
26
+ "lib/app/models/mongoid/grid_fs/fs/chunk.rb",
27
+ "lib/app/models/mongoid/grid_fs/fs/file.rb",
28
+ "lib/mongoid-grid_fs.rb",
29
+ "gnuside-mongoid-grid_fs.gemspec",
30
+ "test",
31
+ "test/helper.rb",
32
+ "test/mongoid-grid_fs_test.rb",
33
+ "test/testing.rb"]
34
+
35
+ spec.executables = []
36
+
37
+ spec.require_path = "lib"
38
+
39
+ spec.test_files = nil
40
+
41
+
42
+ spec.add_dependency(*["mongoid", ">= 3.0", "< 5.0"])
43
+
44
+ spec.add_dependency(*["mime-types", "~> 1.19"])
45
+
46
+
47
+ spec.extensions.push(*[])
48
+
49
+ spec.rubyforge_project = "codeforpeople"
50
+ spec.author = "Ara T. Howard"
51
+ spec.email = "ara.t.howard@gmail.com"
52
+ spec.homepage = "https://github.com/ahoward/mongoid-grid_fs"
53
+ end
@@ -0,0 +1,2 @@
1
+ require 'mongoid-grid_fs.rb' unless defined?(Mongoid::GridFS::Fs::Chunk)
2
+ Mongoid::GridFS::Fs::Chunk
@@ -0,0 +1,2 @@
1
+ require 'mongoid-grid_fs.rb' unless defined?(Mongoid::GridFS::Fs::File)
2
+ Mongoid::GridFS::Fs::File
@@ -0,0 +1,2 @@
1
+ require 'mongoid-grid_fs.rb' unless defined?(Mongoid::GridFS)
2
+ Mongoid::GridFS