Created
May 27, 2011 13:44
-
-
Save adamhunter/995278 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ripple/associations/proxy' | |
require 'ripple/associations/one' | |
module Ripple | |
module Associations | |
class OneKeyProxy < Proxy | |
include One | |
def replace(doc) | |
@reflection.verify_type!(doc, owner) | |
doc.key = owner.key | |
owner.class.__send__(:define_method, "key=") do |value| | |
doc.key = value unless doc.key == value | |
super(value) unless key == value | |
end | |
loaded | |
@target = doc | |
end | |
def find_target | |
klass.find(owner.key) | |
end | |
protected | |
def instantiate_target(instantiator, attrs={}) | |
@target = super | |
@target.key = owner.key | |
@target | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment