Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 61 lines (41 sloc) 1.679 kB
d49af16 @jnunemaker Update readme to use markdown
authored
1 # Toystore Mongo
b4dda4e @jnunemaker Added readme.
authored
2
3 Mongo integration for Toystore.
4
d49af16 @jnunemaker Update readme to use markdown
authored
5 ## Install
b4dda4e @jnunemaker Added readme.
authored
6
d49af16 @jnunemaker Update readme to use markdown
authored
7 ```
8 gem install toystore-mongo
9 ```
b4dda4e @jnunemaker Added readme.
authored
10
d49af16 @jnunemaker Update readme to use markdown
authored
11 ## Usage
688a671 @jnunemaker Updated readme.
authored
12
8a07943 @jnunemaker readme formatting
authored
13 ```ruby
14 class User
15 include Toy::Mongo
16 adapter :mongo, Mongo::Connection.new.db('myapp')['users']
688a671 @jnunemaker Updated readme.
authored
17
8a07943 @jnunemaker readme formatting
authored
18 attribute :name, String
19 end
20 ```
688a671 @jnunemaker Updated readme.
authored
21
22 Including Toy::Mongo includes Toy::Store and then does a few things:
23
24 * Includes Plucky querying so you can do things like User.count, User.all, User.first, and much more
25 * Sets the key factory to object id
26 * Overrides get so that it also works with string representation of object id
27 * Overrides get_multi so that it performs one query instead of one query per id
13c813f @jnunemaker Updated readme about atomic updates.
authored
28
29
30 ### Atomic Updates
31
32 ```ruby
33 class User
34 include Toy::Mongo
35 include Toy::Mongo::AtomicUpdates
36
37 adapter :mongo_atomic, Mongo::Connection.new.db('adapter')['testing']
38
39 attribute :name, String
40 attribute :bio, String
41 end
42
43 user = User.create(:name => 'John', :bio => 'Awesome!')
44 user.name = 'Nunes'
45 user.save # Equivalent to update({:_id => user.id}, {'$set' => {'name' => 'Nunes'}})
46 ```
47
48 Caveat: At this time it only works with simple data types. Complex types like Hash, Array, and Set are not supported. Oddness will ensue if you expect them to work as they can be manipuled through means other than assignment.
688a671 @jnunemaker Updated readme.
authored
49
d49af16 @jnunemaker Update readme to use markdown
authored
50 ## Contributing
b4dda4e @jnunemaker Added readme.
authored
51
52 * Fork the project.
53 * Make your feature addition or bug fix.
54 * Add tests for it. This is important so I don't break it in a future version unintentionally.
55 * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
56 * Send me a pull request. Bonus points for topic branches.
57
d49af16 @jnunemaker Update readme to use markdown
authored
58 ## Copyright
b4dda4e @jnunemaker Added readme.
authored
59
60 See LICENSE for details.
Something went wrong with that request. Please try again.