From 87c771b96e24f38854a858b8ff1758e386cad2e2 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 18 Oct 2012 15:49:06 -0400 Subject: [PATCH] information on creating indexes and hooking into mongoid rake tasks --- README.md | 7 +++++++ lib/mongoid-grid_fs.rb | 7 ++++--- lib/mongoid-grid_fs/railtie.rb | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 lib/mongoid-grid_fs/railtie.rb diff --git a/README.md b/README.md index 7cac23a..117182e 100644 --- a/README.md +++ b/README.md @@ -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`. + diff --git a/lib/mongoid-grid_fs.rb b/lib/mongoid-grid_fs.rb index 25c10c0..28a77ef 100644 --- a/lib/mongoid-grid_fs.rb +++ b/lib/mongoid-grid_fs.rb @@ -51,6 +51,10 @@ require "digest/md5" require "cgi" + + if defined?(::Rails::Railtie) + require 'mongoid-grid_fs/railtie' + end end end @@ -134,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 diff --git a/lib/mongoid-grid_fs/railtie.rb b/lib/mongoid-grid_fs/railtie.rb new file mode 100644 index 0000000..3f16ebe --- /dev/null +++ b/lib/mongoid-grid_fs/railtie.rb @@ -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 +