From 0f6935b01474faf34c9b63af71882267cbf85af4 Mon Sep 17 00:00:00 2001 From: Nate Matykiewicz Date: Mon, 22 Jan 2024 10:30:17 -0600 Subject: [PATCH] Fix: Extensions aren't loaded in development/test PR #19 previously loaded the associated object class when the has_object was defined, so that extensions would get run. It seems like that code got lost in a rebase. So now, extensions only run on boot if eager loading is enabled (which it is in production). Otherwise they aren't loaded until the first time the associated object gets used. --- lib/active_record/associated_object/object_association.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_record/associated_object/object_association.rb b/lib/active_record/associated_object/object_association.rb index 7cc073c..79ea672 100644 --- a/lib/active_record/associated_object/object_association.rb +++ b/lib/active_record/associated_object/object_association.rb @@ -14,7 +14,7 @@ def extend_source_from(chunks, &block) module ClassMethods def has_object(*names, **callbacks) extend_source_from(names) do |name| - "def #{name}; (@associated_objects ||= {})[:#{name}] ||= #{name.to_s.classify}.new(self); end" + "def #{name}; (@associated_objects ||= {})[:#{name}] ||= #{const_get(name.to_s.classify)}.new(self); end" end extend_source_from(names) do |name|