From b8c2dbfc5ee61cd79dfdbf9c3da62bcf0b2b5803 Mon Sep 17 00:00:00 2001 From: evanweaver Date: Wed, 16 Jan 2008 00:07:02 +0000 Subject: [PATCH] changelog; bugfixes for STI children (rsl) git-svn-id: svn://rubyforge.org/var/svn/fauna/has_many_polymorphs/trunk@1354 c1ad287d-65d5-445d-b84c-e64f8492f1e6 --- CHANGELOG | 6 ++---- lib/has_many_polymorphs/autoload.rb | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 233fcb8..0bb49bc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,7 @@ -vSVN. Verify Rails 2.0.1 compatibility with multi_rails. +v2.12. Improvements to the test suite; bugfixes for STI children (rsl). -v2.12. Remove commenting generator (schema choices were not very good). - -v2.11. Rails 1.2.6 tagging generator compatibility; change test suite to use included integration app; include commenting generator (not well tested) [Josh Stephenson]. +v2.11. Rails 1.2.6 tagging generator compatibility; change test suite to use included integration app. v2.10. Add :parent_conditions option; bugfix for nullified conditions; bugfix for self-referential tagging generator; allow setting of has_many_polymorphs_options hash in Configuration's after_initialize if you need to adjust the autoload behavior; clear error message on missing or improperly namespaced models; fix .build on double-sided relationships; add :namespace key for easier set up of Camping apps or other unusual class structures. diff --git a/lib/has_many_polymorphs/autoload.rb b/lib/has_many_polymorphs/autoload.rb index ccee4cd..207bc9a 100644 --- a/lib/has_many_polymorphs/autoload.rb +++ b/lib/has_many_polymorphs/autoload.rb @@ -1,7 +1,7 @@ -require 'initializer' unless defined? Rails::Initializer +require 'dispatcher' -class Rails::Initializer #:nodoc: +module HasManyPolymorphs =begin rdoc Searches for models that use has_many_polymorphs or acts_as_double_polymorphic_join and makes sure that they get loaded during app initialization. This ensures that helper methods are injected into the target classes. @@ -17,7 +17,7 @@ Note that you can override DEFAULT_OPTIONS via Rails::Configuration#has_many_pol =end - module HasManyPolymorphsAutoload + module Autoload DEFAULT_OPTIONS = { :file_pattern => "#{RAILS_ROOT}/app/models/**/*.rb", @@ -29,19 +29,18 @@ Note that you can override DEFAULT_OPTIONS via Rails::Configuration#has_many_pol @@options = HashWithIndifferentAccess.new(DEFAULT_OPTIONS) # Override for Rails::Initializer#after_initialize. - def after_initialize_with_autoload - after_initialize_without_autoload + def self.autoload _logger_debug "autoload hook invoked" - HasManyPolymorphsAutoload.options[:requirements].each do |requirement| + options[:requirements].each do |requirement| require requirement end - Dir[HasManyPolymorphsAutoload.options[:file_pattern]].each do |filename| - next if filename =~ /#{HasManyPolymorphsAutoload.options[:file_exclusions].join("|")}/ + Dir[options[:file_pattern]].each do |filename| + next if filename =~ /#{options[:file_exclusions].join("|")}/ open filename do |file| - if file.grep(/#{HasManyPolymorphsAutoload.options[:methods].join("|")}/).any? + if file.grep(/#{options[:methods].join("|")}/).any? begin model = File.basename(filename)[0..-4].camelize _logger_warn "preloading parent model #{model}" @@ -55,8 +54,9 @@ Note that you can override DEFAULT_OPTIONS via Rails::Configuration#has_many_pol end end - - include HasManyPolymorphsAutoload - alias_method_chain :after_initialize, :autoload +end + +Dispatcher.to_prepare do + HasManyPolymorphs::Autoload.autoload end -- 2.11.4.GIT