lib/active_remote/association.rb in active_remote-2.3.5 vs lib/active_remote/association.rb in active_remote-2.4.0
- old
+ new
@@ -130,10 +130,21 @@
raise "Could not find attribute: '#{options[:scope]}' on #{associated_class}" unless associated_class.public_instance_methods.include?(options[:scope])
end
private
+ def create_setter_method(associated_klass, options={})
+ writer_method = "#{associated_klass}=".to_sym
+ define_method(writer_method) do |new_value|
+ klass_name = options.fetch(:class_name){ associated_klass }
+ klass = klass_name.to_s.classify.constantize
+
+ instance_variable_set(:"@#{new_value.class.name.demodulize.underscore}", new_value)
+ new_value
+ end
+ end
+
def perform_association(associated_klass, options={})
define_method(associated_klass) do
klass_name = options.fetch(:class_name){ associated_klass }
klass = klass_name.to_s.classify.constantize
@@ -146,9 +157,11 @@
instance_variable_set(:"@#{associated_klass}", value)
end
return value
end
+
+ create_setter_method(associated_klass, options)
end
end
end
end