lib/couchrest/model/proxyable.rb in couchrest_model-1.2.0.beta vs lib/couchrest/model/proxyable.rb in couchrest_model-2.0.0.beta

- old
+ new

@@ -15,18 +15,19 @@ # 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]) 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 end - # Tell this model which other model to use a base for the database + # Tell this model which other model to use as a base for the database # connection to use. def proxied_by(model_name, options = {}) raise "Model can only be proxied once or ##{model_name} already defined" if method_defined?(model_name) || !proxy_owner_method.nil? self.proxy_owner_method = model_name attr_accessor :model_proxy @@ -43,9 +44,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 proxied_model_names + @proxied_model_names ||= [] end private # Ensure that no attempt is made to autoload a database connection