rails/init.rb in aiwilliams-mlist-0.1.6 vs rails/init.rb in aiwilliams-mlist-0.1.7

- old
+ new

@@ -1,28 +1,22 @@ -require 'dispatcher' unless defined?(::Dispatcher) - -Dispatcher.module_eval do - # Provides the mechinism to support applications that want to observe MList - # models. - # - # ActiveRecord observers are reloaded at each request in development mode. - # They will be registered with the MList models each time. Since the MList - # models are required once at initialization, there will always only be one - # instance of the model class, and therefore, many instances of the observer - # class registered with it; all but the most recent are invalid, since they - # were undefined when the dispatcher reloaded the application. - # - # Why not an initializer "to_prepare" block? Simply because we must clear - # the observers in the ActiveRecord classes before the - # ActiveRecord::Base.instantiate_observers call is made by the prepare block - # that we cannot get in front of with the initializer approach. Also, it - # lessens the configuration burden of the MList client application. - # - # Should we ever have observers in MList, this will likely need more careful - # attention. - # - def reload_application_with_plugin_record_support - ActiveRecord::Base.send(:subclasses).each(&:delete_observers) - reload_application_without_plugin_record_support +# Provides the mechinism to support applications that want to observe MList +# models. +# +# ActiveRecord observers are reloaded at each request in development mode. +# They will be registered with the MList models each time. Since the MList +# models are required once at initialization, there will always only be one +# instance of the model class, and therefore, many instances of the observer +# class registered with it; all but the most recent are invalid, since they +# were undefined when the dispatcher reloaded the application. +# +# Should we ever have observers in MList, this will likely need more careful +# attention. +# +unless Rails.configuration.cache_classes + class << ActiveRecord::Base + def instantiate_observers_with_mlist_observers + subclasses.each(&:delete_observers) + instantiate_observers_without_mlist_observers + end + alias_method_chain :instantiate_observers, :mlist_observers end - alias_method_chain :reload_application, :plugin_record_support end \ No newline at end of file