Skip to content

Commit

Permalink
*really* avoiding stack overflow (ahem)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahd1 committed Apr 1, 2009
1 parent 60a0903 commit 83bc8bf
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions 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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 83bc8bf

Please sign in to comment.