Skip to content

Instantly share code, notes, and snippets.

@adamhunter
Created March 30, 2010 19:20
Show Gist options
  • Save adamhunter/349474 to your computer and use it in GitHub Desktop.
Save adamhunter/349474 to your computer and use it in GitHub Desktop.
# mongo
def proxy_class
return @proxy_class if defined?(@proxy_class)
@proxy_class =
if many?
if klass.embeddable?
polymorphic? ? ManyEmbeddedPolymorphicProxy : ManyEmbeddedProxy
else
if polymorphic?
ManyPolymorphicProxy
elsif as?
ManyDocumentsAsProxy
elsif in_array?
InArrayProxy
else
ManyDocumentsProxy
end
end
elsif one?
OneProxy
else
polymorphic? ? BelongsToPolymorphicProxy : BelongsToProxy
end
end
# what i am thinking
def proxy_class
return @proxy_class if defined?(@proxy_class)
proxy_class_name.constantize
end
def proxy_class_name
@using ||= klass.embeddable? ? :embedded : :link
(many? ? 'Many' : 'One') + @using.to_s.classify + ('Polymorphic' if polymorphic?).to_s + 'Proxy'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment