Module: CouchRest::Model::Proxyable::ClassMethods
- Defined in:
- lib/couchrest/model/proxyable.rb
Instance Method Summary collapse
-
#proxied_by(model_name, options = {}) ⇒ Object
Tell this model which other model to use a base for the database connection to use.
-
#proxy_database_method(name = nil) ⇒ Object
Define the name of a method to call to determine the name of the database to use as a proxy.
-
#proxy_for(assoc_name, options = {}) ⇒ Object
Define a collection that will use the base model for the database connection details.
- #proxy_owner_method ⇒ Object
-
#proxy_owner_method=(name) ⇒ Object
Define an a class variable accessor ready to be inherited and unique for each Class using the base.
Instance Method Details
#proxied_by(model_name, options = {}) ⇒ Object
Tell this model which other model to use a base for the database connection to use.
29 30 31 32 33 34 35 |
# File 'lib/couchrest/model/proxyable.rb', line 29 def proxied_by(model_name, = {}) 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 attr_accessor model_name overwrite_database_reader(model_name) end |
#proxy_database_method(name = nil) ⇒ Object
Define the name of a method to call to determine the name of the database to use as a proxy.
45 46 47 48 |
# File 'lib/couchrest/model/proxyable.rb', line 45 def proxy_database_method(name = nil) @proxy_database_method = name if name @proxy_database_method end |
#proxy_for(assoc_name, options = {}) ⇒ Object
Define a collection that will use the base model for the database connection details.
17 18 19 20 21 22 23 24 25 |
# File 'lib/couchrest/model/proxyable.rb', line 17 def proxy_for(assoc_name, = {}) db_method = [:database_method] || "proxy_database" [:class_name] ||= assoc_name.to_s.singularize.camelize class_eval <<-EOS, __FILE__, __LINE__ + 1 def #{assoc_name} @#{assoc_name} ||= CouchRest::Model::Proxyable::ModelProxy.new(::#{[:class_name]}, self, self.class.to_s.underscore, #{db_method}) end EOS end |
#proxy_owner_method ⇒ Object
41 |
# File 'lib/couchrest/model/proxyable.rb', line 41 def proxy_owner_method; @proxy_owner_method; end |
#proxy_owner_method=(name) ⇒ Object
Define an a class variable accessor ready to be inherited and unique for each Class using the base. Perhaps there is a shorter way of writing this.
40 |
# File 'lib/couchrest/model/proxyable.rb', line 40 def proxy_owner_method=(name); @proxy_owner_method = name; end |