Skip to content
Easily add and configure plugins for Mongoid
Ruby
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
autotest
lib/mongoid
spec
.gitignore
.rspec
Gemfile
Gemfile.lock
LICENSE
README.rdoc
Rakefile
mongoid-plugins.gemspec

README.rdoc

mongoid-plugins

Easily add and configure plugins for Mongoid

Requirements

  • mongoid (>= 2.0.0.beta.20)

Install

To install mongoid-plugins, simply add it to your Gemfile:

gem 'mongoid-plugins', :require => 'mongoid/plugins'

In order to get the latest development version of mongoid-plugins:

gem 'mongoid-plugins', :git => 'git://github.com/benedikt/mongoid-plugins', :require => 'mongoid/plugins'

You might want to remove the :require => 'mongoid/plugins' option and explicitly require 'mongoid/plugins' where needed and finally run

bundle install

Usage

class SomeDocument
  include Mongoid::Document

  plugin SomePlugin do |c|
    c.some_setting = false
  end
end

Writing Plugins

It's fairly easy to write plugins compatible with Mongoid::Plugins. In fact they're simply Ruby modules. It's possible to add default options by defining a default_plugin_options method on your module returning a hash:

module SomePlugin
  def self.default_plugin_options
    {
      :some_default_setting => 100
    }
  end
end

To access the options from within your plugin just call plugin_options_for(SomePlugin):

module SomePlugin
  def a_plugin_method
    if self.plugin_options_for(SomePlugin).do_something
      # Do something :-)
    end
  end
end

Known issues

See github.com/benedikt/mongoid-plugins/issues

Repository

See github.com/benedikt/mongoid-plugins and feel free to fork it!

Copyright

Copyright © 2010 Benedikt Deicke. See LICENSE for details.

Something went wrong with that request. Please try again.