Permalink
Browse files

enable Bullet::Mongoid only for project depends on mongoid

  • Loading branch information...
1 parent d2ab287 commit 11eeec406479a5e210b64a93a10ccc83a3ebf4f0 @flyerhzm committed May 7, 2012
Showing with 9 additions and 7 deletions.
  1. +8 −4 lib/bullet.rb
  2. +1 −3 lib/bullet/detector/association.rb
View
@@ -41,11 +41,15 @@ class <<self
def enable=(enable)
@enable = enable
if enable?
- Bullet::ActiveRecord.enable
- if Rails.version =~ /\A2./
- Bullet::ActionController.enable
+ begin
+ require 'mongoid'
+ Bullet::Mongoid.enable
+ rescue LoadError
+ Bullet::ActiveRecord.enable
+ if Rails.version =~ /\A2./
+ Bullet::ActionController.enable
+ end
end
- Bullet::Mongoid.enable
end
end
@@ -30,10 +30,8 @@ def add_call_object_associations(object, associations)
def add_possible_objects(object_or_objects)
if object_or_objects.is_a? Array
object_or_objects.each { |object| possible_objects.add object.bullet_ar_key }
- elsif object_or_objects.is_a? ::ActiveRecord::Base
- possible_objects.add object_or_objects.bullet_ar_key if object_or_objects.id
else
- # do nothing
+ possible_objects.add object_or_objects.bullet_ar_key if object_or_objects.id
end
end

0 comments on commit 11eeec4

Please sign in to comment.