use terrible hacks to make this work when rails tries to marshal

This commit is contained in:
Charlie Somerville
2013-10-25 17:01:46 -04:00
parent 4bb1d3ef20
commit ca90ecf2cb
2 changed files with 11 additions and 8 deletions

View File

@@ -51,14 +51,16 @@ module ActiveRecord
instance_methods.each { |m| undef_method m unless m.to_s =~ /^(?:nil\?|send|object_id)$|^__|^respond_to_missing|proxy_/ }
def self.new(owner, reflection)
klass = if reflection.options[:extend]
reflection.instance_variable_get(:@_extend_class) ||
reflection.instance_variable_set(:@_extend_class, Class.new(self) do
include *reflection.options[:extend]
end)
else
self
end
klass =
reflection.cached_extend_class ||=
if reflection.options[:extend]
const_name = "AR_CACHED_EXTEND_CLASS_#{reflection.name}_#{reflection.options[:extend].join("_")}"
reflection.active_record.const_set(const_name, Class.new(self) do
include *reflection.options[:extend]
end)
else
self
end
proxy = klass.allocate
proxy.send(:initialize, owner, reflection)

View File

@@ -77,6 +77,7 @@ module ActiveRecord
# those classes. Objects of AggregateReflection and AssociationReflection are returned by the Reflection::ClassMethods.
class MacroReflection
attr_reader :active_record
attr_accessor :cached_extend_class
def initialize(macro, name, options, active_record)
@macro, @name, @options, @active_record = macro, name, options, active_record