lib/amoeba.rb in amoeba-2.0.0 vs lib/amoeba.rb in amoeba-2.1.0
- old
+ new
@@ -292,10 +292,14 @@
# Config Getters {{{
def amoeba_conf
self.class.amoeba
end
+ def amoeba_dup_options
+ @amoeba_dup_options
+ end
+
def has_parent_amoeba_conf?
self.class.superclass.respond_to?(:amoeba)
end
def parent_amoeba_conf
@@ -323,10 +327,11 @@
end
# }}}
def amoeba_dup(options={})
@result = self.dup()
+ @amoeba_dup_options = options
# Inherit Parent Settings {{{
if !amoeba_conf.enabled && parent_amoeba_conf.inherit
if amoeba_conf.upbringing
parenting_style = amoeba_conf.upbringing
@@ -381,19 +386,19 @@
amo_process_association(i, r)
end
# }}}
# Exclusive Style {{{
elsif amoeba_conf.excludes.count > 0
- reflections.each do |r|
+ self.class.reflections.each do |r|
if not amoeba_conf.excludes.include?(r[0])
amo_process_association(r[0], r[1])
end
end
# }}}
# Indiscriminate Style {{{
else
- reflections.each do |r|
+ self.class.reflections.each do |r|
amo_process_association(r[0], r[1])
end
end
# }}}
end
@@ -420,11 +425,11 @@
end
old_obj = self.send(relation_name)
if not old_obj.nil?
- copy_of_obj = old_obj.amoeba_dup
+ copy_of_obj = old_obj.amoeba_dup(amoeba_dup_options)
copy_of_obj[:"#{settings.foreign_key}"] = nil
@result.send(:"#{relation_name}=", copy_of_obj)
end
when :has_many
@@ -452,10 +457,10 @@
# association is really just for convenience usage
# on the model
return if settings.is_a?(ActiveRecord::Reflection::ThroughReflection)
self.send(relation_name).each do |old_obj|
- copy_of_obj = old_obj.amoeba_dup
+ copy_of_obj = old_obj.amoeba_dup(amoeba_dup_options)
copy_of_obj[:"#{settings.foreign_key}"] = nil
# associate this new child to the new parent object
@result.send(relation_name) << copy_of_obj
end