Module: Tenacity::OrmExt::CouchRest

Defined in:
lib/tenacity/orm_ext/couchrest.rb

Overview

Tenacity relationships on CouchRest objects require no special keys defined on the object. Tenacity will define the keys that it needs to support the relationships. Take the following class for example:

class Car < CouchRest::ExtendedDocument
  include Tenacity

  t_has_many    :wheels
  t_has_one     :dashboard
  t_belongs_to  :driver
end

t_belongs_to

The t_belongs_to association will define a property named after the association. The example above will create a property named :driver_id

t_has_one

The t_has_one association will not define any new properties on the object, since the associated object holds the foreign key.

t_has_many

The t_has_many association will define a property named after the association. The example above will create a property named :wheels_ids

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.setup(model) ⇒ Object

:nodoc:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/tenacity/orm_ext/couchrest.rb', line 34

def self.setup(model) #:nodoc:
  begin
    require 'couchrest_model'
    if model.ancestors.include?(::CouchRest::Model::Base)
      model.send :include, CouchRest::InstanceMethods
      model.extend CouchRest::ClassMethods
    end
  rescue LoadError
    # CouchRest::Model not available
  end

  begin
    require 'couchrest_extended_document'
    if model.ancestors.include?(::CouchRest::ExtendedDocument)
      model.send :include, CouchRest::InstanceMethods
      model.extend CouchRest::ClassMethods
    end
  rescue LoadError
    # CouchRest::ExtendedDocument not available
  end

  # For pre 1.0 versions of couchrest
  begin
    require 'couchrest'
    if model.ancestors.include?(::CouchRest::ExtendedDocument)
      model.send :include, CouchRest::InstanceMethods
      model.extend CouchRest::ClassMethods
    end
  rescue LoadError
  rescue NameError
    # CouchRest::ExtendedDocument not available
  end
end