Skip to content
Browse files

*really* avoiding stack overflow (ahem)

  • Loading branch information...
1 parent 60a0903 commit 83bc8bffba69e761520120979f55320579fc6a52 @noahd1 committed
Showing with 23 additions and 10 deletions.
  1. +23 −10 lib/oink/rails/instance_type_counter.rb
View
33 lib/oink/rails/instance_type_counter.rb
@@ -1,4 +1,13 @@
module Oink
+
+ def self.extended_active_record?
+ @oink_extended_active_record
+ end
+
+ def self.extended_active_record!
+ @oink_extended_active_record = true
+ end
+
module InstanceTypeCounter
def self.included(klass)
ActiveRecord::Base.send(:include, OinkInstanceTypeCounterInstanceMethods)
@@ -45,18 +54,22 @@ def self.instantiated_hash
def self.total_objects_instantiated
@@total ||= @@instantiated.inject(0) { |i, j| i + j.last }
end
-
- if instance_methods.include?("after_initialize")
- def after_initialize_with_oink
- after_initialize_without_oink
- increment_ar_count
- end
- alias_method_chain :after_initialize, :oink unless instance_methods.include?(:after_initialize_with_oink)
- else
- def after_initialize
- increment_ar_count
+ unless Oink.extended_active_record?
+ if instance_methods.include?("after_initialize")
+ def after_initialize_with_oink
+ after_initialize_without_oink
+ increment_ar_count
+ end
+
+ alias_method_chain :after_initialize, :oink
+ else
+ def after_initialize
+ increment_ar_count
+ end
end
+
+ Oink.extended_active_record!
end
end

0 comments on commit 83bc8bf

Please sign in to comment.
Something went wrong with that request. Please try again.