mongo_mapper_tree
This is an maintained version of mongo_mapper_acts_as_tree (github.com/ramdiv/mongo_mapper_acts_as_tree) (ie. most of the code is written by Jacob Vidmar) In it’s essence it’s an implementation of a tree structure for MongoMapper, think acts as tree but for mongodb.
Installation
Install as gem
gem install mongo_mapper_tree
Usage
Enable the tree functionality by declaring acts_as_tree on your model
class Category
include MongoMapper::Document
plugin MongoMapper::Plugins::Tree
key :name, String
end
This adds class_attributes called parent_id_field, path_field, depth_field, tree_order and tree_search_class.
parent_id_field, path_field and depth_field overrides the default field names
tree_order controls the order (format :field_name.[asc|desc])
tree_search_class expects a Class that is a MongoMapper::Document to be used for search
Check test_tree.rb and test_search_class.rb for examples.
For best performance add a index on the field called path_field.
Note on Patches/Pull Requests
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
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)
-
Send me a pull request. Bonus points for topic branches.
Copyright
Original code written by Jakob Vidmar github.com/ramdiv/mongo_mapper_acts_as_tree Copyright © 2011 Joel Junström. See LICENSE for details.