Module: CouchRest::Model::Proxyable::ClassMethods

Defined in:
lib/couchrest/model/proxyable.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) proxied_by(model_name, options = {})

Tell this model which other model to use as a base for the database connection to use.



30
31
32
33
34
35
36
# File 'lib/couchrest/model/proxyable.rb', line 30

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
  attr_accessor model_name
  overwrite_database_reader(model_name)
end

- (Object) proxied_model_names



51
52
53
# File 'lib/couchrest/model/proxyable.rb', line 51

def proxied_model_names
  @proxied_model_names ||= []
end

- (Object) proxy_database_method(name = nil)

Define the name of a method to call to determine the name of the database to use as a proxy.



46
47
48
49
# File 'lib/couchrest/model/proxyable.rb', line 46

def proxy_database_method(name = nil)
  @proxy_database_method = name if name
  @proxy_database_method
end

- (Object) proxy_for(assoc_name, options = {})

Define a collection that will use the base model for the database connection details.



17
18
19
20
21
22
23
24
25
26
# File 'lib/couchrest/model/proxyable.rb', line 17

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

- (Object) proxy_owner_method



42
# File 'lib/couchrest/model/proxyable.rb', line 42

def proxy_owner_method; @proxy_owner_method; end

- (Object) proxy_owner_method=(name)

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.



41
# File 'lib/couchrest/model/proxyable.rb', line 41

def proxy_owner_method=(name); @proxy_owner_method = name; end