mm-commentable

A simple MongoMapper plugin to make adding comments to your models easy

v1.2 is a mongomapper 0.9.0 update to support the new plugin system if you are using mongomapper 0.8.x please use version 1.1 of the gem

Usage

Install the gem

gem install mm-commentable

Or add it to your Gemfile

gem 'mm-commentable'

Then add the commentable plugin to you MongoMapper::Document

class Post
  include MongoMapper::Document
  plugin MongoMapper::Plugins::Commentable

  def on_add_comment(comment)
    do something when a comment is added...
  end
end

You must implement the on_add_comment callback! - however it can be an empty implementation It is called when a valid comment is added to the commentable item with add_comment!

@post = Post.create
@commentor = User.create

@post.add_comment!("great post..", @user)

@post.comments_count # => 1
@posts.comments # => [<Comment>]

The commentor association is polymorphic, so any class will probably work, I expect the commentor would normally be an instance of class <User>, but it could be a <Person> or an <Account> and it will still work

Contributing to mm-commentable

Copyright © 2010 Luke Cunningham. See LICENSE.txt for further details.