lib/initializers/mongoid.rb in tabulatr-0.3.0 vs lib/initializers/mongoid.rb in tabulatr-0.4.0

- old
+ new

@@ -19,17 +19,19 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ -# This is somewhat ugly, for it creates the Mongoid module, no matter -# whether it's about to be used. So you will find an empty Mongoid -# module in every Tabulatr project. -module Mongoid - module Document - module ClassMethods - def find_for_table(params, opts={}, &block) - Tabulatr::Finder.find_for_table(self, params, opts, &block) +# ensure mongoid is loaded *before* monkeypatching +begin; require 'mongoid'; rescue LoadError; end + +if defined? ::Mongoid + module Mongoid + module Document + module ClassMethods + def find_for_table(params, opts={}, &block) + Tabulatr::Finder.find_for_table(self, params, opts, &block) + end end end end -end +end \ No newline at end of file