README.md in gitmodel-0.0.6 vs README.md in gitmodel-0.0.7
- old
+ new
@@ -54,11 +54,13 @@
See the "To do" section below for details, but the main thing that needs
finishing is support for querying. Right now you can find an instance by it's
id, but there is incomplete support (90% complete) for querying, e.g.:
- Post.find(:category => 'ruby', :date => lambda{|d| d > 1.month.ago} :order_by => :date, :order => :asc, :limit => 5)
+```ruby
+Post.find(:category => 'ruby', :date => lambda{|d| d > 1.month.ago} :order_by => :date, :order => :asc, :limit => 5)
+```
This includes support for indexing all attributes so that queries don't need to
load every object.
@@ -71,48 +73,50 @@
Usage
-----
- GitModel.db_root = '/tmp/gitmodel-data'
- GitModel.create_db!
+```ruby
+GitModel.db_root = '/tmp/gitmodel-data'
+GitModel.create_db!
- class Post
- include GitModel::Persistable
+class Post
+ include GitModel::Persistable
- attribute :title
- attribute :body
- attribute :categories, :default => []
- attribute :allow_comments, :default => true
+ attribute :title
+ attribute :body
+ attribute :categories, :default => []
+ attribute :allow_comments, :default => true
- blob :image
- end
+ blob :image
+end
- p1 = Post.new(:id => 'lessons-learned', :title => 'Lessons learned', :body => '...')
- p1.image = some_binary_data
- p1.save!
+p1 = Post.new(:id => 'lessons-learned', :title => 'Lessons learned', :body => '...')
+p1.image = some_binary_data
+p1.save!
- p = Post.find('lessons-learned')
+p = Post.find('lessons-learned')
- p2 = Post.new(:id => 'hotdog-eating-contest', :title => 'I won!')
- p2.body = 'This weekend I won a hotdog eating contest!'
- p2.image = some_binary_data
- p2.blobs['hotdogs.jpg'] = some_binary_data
- p2.blobs['the-aftermath.jpg'] = some_binary_data
- p2.save!
+p2 = Post.new(:id => 'hotdog-eating-contest', :title => 'I won!')
+p2.body = 'This weekend I won a hotdog eating contest!'
+p2.image = some_binary_data
+p2.blobs['hotdogs.jpg'] = some_binary_data
+p2.blobs['the-aftermath.jpg'] = some_binary_data
+p2.save!
- p3 = Post.create!(:id => 'running-with-scissors', :title => 'Running with scissors', :body => '...')
+p3 = Post.create!(:id => 'running-with-scissors', :title => 'Running with scissors', :body => '...')
- p4 = Post.find('running-with-scissors')
+p4 = Post.find('running-with-scissors')
- class Comment
- include GitModel::Persistable
- attribute :text
- end
+class Comment
+ include GitModel::Persistable
+ attribute :text
+end
- c1 = Comment.create!(:id => '2010-01-03-328', :text => '...')
- c2 = Comment.create!(:id => '2010-05-29-742', :text => '...')
+c1 = Comment.create!(:id => '2010-01-03-328', :text => '...')
+c2 = Comment.create!(:id => '2010-05-29-742', :text => '...')
+```
An example of a project that uses GitModel is [Balisong](https://github.com/pauldowman/balisong), a blogging app for coders (but it doesn't save objects to the data store. It's read-only so far, assuming that posts will be edited with a text editor).
@@ -154,35 +158,38 @@
Performance
-----------
GitModel supports memcached for query results. This is off by default, but can be configured like this:
- GitModel.memcache_servers(['server_1', 'server_2', ...])
- GitModel.memcache_namespace('optional_namespace')
+```ruby
+GitModel.memcache_servers(['server_1', 'server_2', ...])
+GitModel.memcache_namespace('optional_namespace')
+```
The namespace is optional, and usually not necessary because GitModel will prepend the last segment of GitModel.db_root anyway.
A Git SHA is also prepended to every key, so that outdated versions will not be retrieved from the cache. This is the SHA of the latest commit so unfortunately this is only useful when there are not frequent commits because every commit invalidates the cache. (This is obviously not ideal and I'm sure it can be improved upon.)
There is still a lot of work to be done to make it faster. First, some analysis is required, but some guesses about things that would help are:
- * Use [Rugged](https://github.com/libgit2/rugged) instead of Grit
- * Remove the transaction lock (see transaction.rb line 19)
- * Ability to iterate over result set without eager loading of all instances
+* Use [Rugged](https://github.com/libgit2/rugged) instead of Grit
+* Remove the transaction lock (see transaction.rb line 19)
+* Ability to iterate over result set without eager loading of all instances
Contributing
------------
Do you have an improvement to make? Please submit a pull request on GitHub or a
patch, including a test written with RSpec. To run all tests simply run
-`autospec`.
+`autotest`.
The main author is [Paul Dowman](http://pauldowman.com/about) ([@pauldowman](http://twitter.com/pauldowman)).
Thanks to everyone who has contributed so far:
* [Alex Bartlow](https://github.com/alexbartlow)
+* [Daniel Russo](https://github.com/drusso)
To do
-----