Module: Correlate
- Defined in:
- lib/correlate.rb,
lib/correlate/links.rb,
lib/correlate/validator.rb,
lib/correlate/correlation.rb,
lib/correlate/relationships.rb,
lib/correlate/relationships/couchrest.rb,
lib/correlate/relationships/active_record.rb,
lib/correlate/relationships/active_record/collection_proxy.rb
Overview
Correlate
Correlate is an experiment in loosely defining relationships between documents stored in CouchDB using CouchRest’s ExtendedDocument, as well as relationships between these documents and ActiveRecord models.
Overview
Relationships are defined as an array of hashes, each hash containing a rel
and href
key. This is modelled on HTML’s success in loosely defining relationships between different documents.
A sample might look like this:
{
...
"links" : [
{ "rel" : "another_doc", "href" : "<uuid>" },
{ "rel" : "important", "href" : "<uuid>" }
...
]
...
}
Using correlate
Correlate presents itself as a mixin for CouchRest::ExtendedDocument classes, as well as ActiveRecord models.
Using with CouchRest::ExtendedDocument
class SomeDocument < CouchRest::ExtendedDocument
include Correlate
do
some :other_documents, :class => 'OtherDocument', :rel => 'other_document'
a :parent_document, :class => 'ParentDocument'
end
end
Using with ActiveRecord::Base
class Model < ActiveRecord::Base
include Correlate
do
some :documents, :class => 'Document', :rel => 'model'
end
end
When correlating ActiveRecord models with CouchRest documents, it is required that the ‘reverse correlation’ is specified in the CouchRest class.
Defined Under Namespace
Modules: ClassMethods, Relationships Classes: Correlation, Links, Validator
Constant Summary collapse
- VERSION =
'0.1.1'
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
67 68 69 |
# File 'lib/correlate.rb', line 67 def self.included( base ) base.extend( ClassMethods ) end |