lib/couchrest/model/proxyable.rb in couchrest_model-2.0.3 vs lib/couchrest/model/proxyable.rb in couchrest_model-2.0.4
- old
+ new
@@ -15,11 +15,12 @@
# Define a collection that will use the base model for the database connection
# details.
def proxy_for(assoc_name, options = {})
db_method = options[:database_method] || "proxy_database"
options[:class_name] ||= assoc_name.to_s.singularize.camelize
- proxied_model_names << options[:class_name] unless proxied_model_names.include?(options[:class_name])
+ proxy_method_names << assoc_name.to_sym unless proxy_method_names.include?(assoc_name.to_sym)
+ proxied_model_names << options[:class_name] unless proxied_model_names.include?(options[:class_name])
class_eval <<-EOS, __FILE__, __LINE__ + 1
def #{assoc_name}
@#{assoc_name} ||= CouchRest::Model::Proxyable::ModelProxy.new(::#{options[:class_name]}, self, self.class.to_s.underscore, #{db_method})
end
EOS
@@ -44,9 +45,13 @@
# Define the name of a method to call to determine the name of
# the database to use as a proxy.
def proxy_database_method(name = nil)
@proxy_database_method = name if name
@proxy_database_method
+ end
+
+ def proxy_method_names
+ @proxy_method_names ||= []
end
def proxied_model_names
@proxied_model_names ||= []
end