Module CouchObject::Persistable::ClassMethods
In: lib/couch_object/persistable.rb
Enumerable Document StandardError HasManyAssociationError MissingView CantCompareSize DocumentNotFound BelongsToAssociationError HasOneAssociationError CouchDBError MapProcessError DatabaseSaveFailed NoDatabaseLocationSet Array HasManyRelation Response Database Server View Errors VERSION ClassMethods Persistable Utils CouchObject dot/f_3.png

Methods

Public Instance methods

get(id, db_uri = self.location)

Alias for get_by_id

Loads a document from the database

Aliases:

Takes:

  • id: the ID of the document that should be loaded
  • db_uri: the uri to the database. Is optional if the database has been defined on class level:
      class SomeClass
        include CouchObject::Persistable
        database 'http://localhost:5984'
      end
    

Returns:

  • a fully initialized class of type self

Raises:

Loads all document from a given view from the database

Takes:

  • view (string): the name of the view to call
  • [params] (hash): a hash of URL query arguments supported by couchDB. If omitted it defaults to not use a key and not update the view. Additionally the db_uri can be set as a parameter if it hasn‘t been defined at class level.

    Example:

      AppleTree.get_from_view("foo_view",
        { :db_uri => "http://localhost:5984/mydb",
          :update => false, :key => "bar"}) => Array
    

Returns:

  • a array of initialized classes (if the view includes the documents full content)

Raises:

Takes, returns and raises the same things as get_by_id

Creates a new object that is forced into smart save mode although the class it is stemming from might not have smart saving enabled.

Protected Instance methods

This recursive method initializes new instances of self and makes sure all sub classes are also initialized.

Takes:

  • A hash of parameters loaded from CoachDB

Returns:

  • An fully initialized object

Raises:

  • Does currently not raise any error

[Validate]