Compare commits

...

2 Commits

5 changed files with 35 additions and 6 deletions

View File

@ -1,10 +1,12 @@
NAME
----
mongoid-sequence
mongoid-grid_fs
INSTALL
-------
gem install mongoid-sequence
gem install mongoid-grid_fs
SYNOPSIS
--------
@ -33,3 +35,8 @@ DESCRIPTION
-----------
mongoid_sequence is a pure mongoid sequence generator based on mongodb's
increment operator
GRIDFS
------
Be sure to create indexes for the GridFS collections with `rake db:mongoid:create_indexes`.

View File

@ -51,6 +51,10 @@
require "digest/md5"
require "cgi"
if defined?(::Rails::Railtie)
require 'mongoid-grid_fs/railtie'
end
end
end
@ -58,6 +62,8 @@
#
module Mongoid
class GridFS
DEFAULT_CHUNK_SIZE = 256 * 1024
class << GridFS
attr_accessor :namespace
attr_accessor :file_model
@ -132,9 +138,6 @@
namespace.send(:const_set, :File, file_model)
namespace.send(:const_set, :Chunk, chunk_model)
#at_exit{ file_model.create_indexes rescue nil }
#at_exit{ chunk_model.create_indexes rescue nil }
const_get(const)
end
@ -293,7 +296,7 @@
field(:contentType, :type => String, :default => 'application/octet-stream')
field(:length, :type => Integer, :default => 0)
field(:chunkSize, :type => Integer, :default => (256 * (2 ** 20)))
field(:chunkSize, :type => Integer, :default => DEFAULT_CHUNK_SIZE)
field(:uploadDate, :type => Date, :default => Time.now.utc)
field(:md5, :type => String, :default => Digest::MD5.hexdigest(''))

View File

@ -0,0 +1,18 @@
module Mongoid
class GridFS
class Railtie < ::Rails::Railtie
rake_tasks do
task 'db:mongoid:create_indexes' do
::Mongoid::GridFS::Fs::File.create_indexes
::Mongoid::GridFS::Fs::Chunk.create_indexes
end
task 'db:mongoid:remove_indexes' do
::Mongoid::GridFS::Fs::File.remove_indexes
::Mongoid::GridFS::Fs::Chunk.remove_indexes
end
end
end
end
end

View File

@ -2,6 +2,7 @@
require 'pp'
require_relative 'testing'
require_relative '../lib/mongoid-sequence.rb'
require_relative '../lib/mongoid-grid_fs.rb'
Mongoid.configure do |config|
config.connect_to('mongoid-sequence')

View File

@ -70,7 +70,7 @@ Testing Mongoid::GridFs do
path = 'a.rb'
data = IO.read(__FILE__)
sio = SIO.new(path, data)
sio = StringIO.new(data)
g = assert{ GridFs[path] = sio and GridFs[path] }
@ -79,7 +79,7 @@ Testing Mongoid::GridFs do
before = GridFs::File.count
assert{ GridFs[path] = SIO.new(path, 'foobar') }
assert{ GridFs[path] = StringIO.new('foobar') }
assert{ GridFs[path].data == 'foobar' }
after = GridFs::File.count