mongoid_cached_document 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,56 @@
1
- = mongoid_cached_document
1
+ = About Mongoid::CachedDocument
2
2
 
3
- Description goes here.
3
+ Mongoid is an ODM (Object-Document-Mapper) framework for MongoDB in Ruby. Mongoid::CachedDocument adds a new field type of the same name that supports the caching attributes from a related document.
4
+
5
+ == Example
6
+
7
+ class User
8
+ include Mongoid::Document
9
+
10
+ field :login
11
+ #...
12
+ end
13
+
14
+ class Post
15
+ include Mongoid::Document
16
+
17
+ field :title
18
+ field :body
19
+ field :author, :type => Mongoid::CachedDocument
20
+ end
21
+
22
+ Assuming <tt>@user</tt> is a valid <tt>User</tt> with an <tt>id</tt> of 42 and <tt>login</tt> of '<tt>jsmith</tt>':
23
+
24
+ @post = Post.create(:title => 'First Post', :body => 'This is a post.', :author => @user)
25
+
26
+ This will create a new <tt>Post</tt> document, with an <tt>author</tt> field, the content of which is a hash:
27
+
28
+ { '_type' => 'User', '_id' = 1 }
29
+
30
+ @post.author._type
31
+ => 'User'
32
+ @post.author._id
33
+ => 1
34
+
35
+ Attempting to get the user's <tt>login</tt> will cause the real user document to be fetched from the collection, which replaces the cached values.
36
+
37
+ class User
38
+ #...
39
+
40
+ def cached_attributes
41
+ [ :login ]
42
+ end
43
+ end
44
+
45
+ With the above class definition, the cached attributes will be:
46
+
47
+ { '_type' => 'User', '_id' = 1, 'login' => 'jsmith' }
48
+
49
+ To use the above in a criteria:
50
+
51
+ Post.criteria.where('author.login' => 'jsmith')
52
+
53
+ Enjoy!
4
54
 
5
55
  == Note on Patches/Pull Requests
6
56
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid_cached_document}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matthew Gibbons"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Matthew Gibbons