lib/mongo_mapper.rb in mongo_mapper-0.5.2 vs lib/mongo_mapper.rb in mongo_mapper-0.5.3

- old
+ new

@@ -1,10 +1,10 @@ require 'rubygems' gem 'activesupport' gem 'mongo', '0.15.1' -gem 'jnunemaker-validatable', '1.7.3' +gem 'jnunemaker-validatable', '1.7.4' require 'activesupport' require 'mongo' require 'validatable' @@ -38,9 +38,24 @@ if @@database_name.blank? raise 'You forgot to set the default database name: MongoMapper.database = "foobar"' end @@database ||= MongoMapper.connection.db(@@database_name) + end + + def self.ensured_indexes + @@ensured_indexes ||= [] + end + + def self.ensure_index(klass, keys, options={}) + ensured_indexes << {:klass => klass, :keys => keys, :options => options} + end + + def self.ensure_indexes! + ensured_indexes.each do |index| + unique = index[:options].delete(:unique) + index[:klass].collection.create_index(index[:keys], unique) + end end module Finders def dynamic_find(finder, args) attributes = {} \ No newline at end of file