README.markdown in couchpillow-0.4.6 vs README.markdown in couchpillow-0.4.7
- old
+ new
@@ -73,35 +73,44 @@
### Document-Level Directives
The following are directives that can be used to trigger specific behaviors
at the Document level.
-* `type(T)`
+* `type T`
Set the type of the Document.
-* `type_prefix(true|false)`
+* `type_prefix true|false`
Default to `true`. If set to false, it removes prefixing document id with
the document type. Leaving this to true is the recommended behavior to avoid
id conflicts between different types of documents, especially when custom
ids are being used.
-* `attribute(name, &block)`
+* `attribute name, &block`
Declares an attribute for this Document. You can specify additional
directives for each attribute. See Attributes section.
-* `db(connection)`
+* `db connection`
Sets the database connections. If set once, it will set that connection as
the primary connection. Any subsequent calls to this directive will set
those connections as secondary connections. See Multiple DB Connections
section.
+* `rename`
+ Rename keys. See Migration section.
+* `migrate`
+
+ Migrate the value of a key. This gets triggered when Document is initialized.
+ See Migration section.
+
+
+
### Attributes
Using Attribute Directive:
class User < CouchPillow::Document
@@ -222,20 +231,36 @@
Using `rename` to rename keys. Useful to maintain document integrity
after a migration.
class User < CouchPillow::Document
- rename :username, :nickname
+ rename :username => :nickname
attribute :nickname
end
u = User.new( { :username => 'jdoe' } )
u.nickname # 'jdoe'
Rename triggers per-document basis. You can use this on a separate script
that queries each document in the database and updates them, or you can
simply use this inside your application code, so it only migrates the document
as it reads them.
+You can also migrate the values. The `migrate` directive is trigger when
+Document is initialized, but after the `rename`.
+This is useful if you have Documents whose values are in the old format
+and you want to convert them.
+
+ class User < CouchPillow::Document
+ rename :nickname => :nicknames
+
+ attribute :nicknames
+
+ migrate :nicknames do |v|
+ v.class == String ? [v] : v
+ end
+ end
+ u = User.new( { :nickname => 'jdoe' } )
+ u.nicknames # ['jdoe']
## Design Docs and Views
Design Docs and Views are outside the scope of CouchPillow.