Sha256: e04dcef8456eaefcbd9187230a5990c803355027dad3579d3e5a14a1acf909c6

Contents?: true

Size: 1.11 KB

Versions: 11

Compression:

Stored size: 1.11 KB

Contents

module Bullet
  module Detector
    class Counter < Base
      def self.clear
        @@possible_objects = nil
        @@impossible_objects = nil
      end

      def self.add_counter_cache(object, associations)
        if conditions_met?( object, associations )
          create_notification object.class, associations
        end
      end

      def self.add_possible_objects(objects)
        possible_objects.add objects
      end

      def self.add_impossible_object(object)
        impossible_objects.add object
      end
      
      private
      def self.create_notification( klazz, associations )
         notice = Bullet::Notification::CounterCache.new klazz, associations
         Bullet.notification_collector.add notice
      end

      def self.possible_objects
        @@possible_objects ||= Bullet::Registry::Object.new
      end

      def self.impossible_objects
        @@impossible_objects ||= Bullet::Registry::Object.new
      end

      def self.conditions_met?( object, associations )
        possible_objects.contains?( object ) and
        !impossible_objects.contains?( object )
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
bullet-2.2.1 lib/bullet/detector/counter.rb
bullet-2.2.0 lib/bullet/detector/counter.rb
bullet-2.1.0 lib/bullet/detector/counter.rb
thaold-bullet-2.0.2 lib/bullet/detector/counter.rb
bullet-2.0.1 lib/bullet/detector/counter.rb
bullet-2.0.0 lib/bullet/detector/counter.rb
bullet-2.0.0.rc3 lib/bullet/detector/counter.rb
bullet-2.0.0.rc2 lib/bullet/detector/counter.rb
bullet-2.0.0.rc1 lib/bullet/detector/counter.rb
bullet-2.0.0.beta.4 lib/bullet/detector/counter.rb
bullet-2.0.0.beta.3 lib/bullet/detector/counter.rb