No commit activity in last 3 years
No release in over 3 years
Helper to facilitate inclusion of namespaced documents in another Mongoid Document
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
~> 0.9
~> 2.6.0
~> 0.7.4

Runtime

>= 2.4
 Project Readme

Mongoid::Included

Helper module to embed documents using the parent's namespace while preserving url helpers consistency. This is useful to organize your project if you heavily rely on embedded documents. This gem concerns the issue 1429 of rails repository: rails/rails#1429 Works with Mongoid 2.4 and ActiveModel 3.2.0.

Installation

Add the gem to your Bundler Gemfile:

gem 'mongoid-included'

Or install with RubyGems:

$ gem install mongoid-included

Usage

In your embedded model:

# Include the helper module
include Mongoid::DocumentInclusion

# Define parent document in embedded class
included_in :invoice

In your parent model:

# Define embedded relation in parent document
includes_many :items
includes_one :user

Example

class Invoice
	include Mongoid::Document
	
	includes_many :items
end

# This will generate a Mongoid Relation with the following signature:
	embeds_many :items, :class_name => Invoice::Item

class Invoice::Item
	include Mongoid::Document

	included_in :invoice
end
# This will generate the following code:
	extend ActiveModel::Naming
	# Overriding .model_name so rails recognizes the class as __Item__ and generate more convenient urls.
	def self.model_name
		if self.parent != Object
			ActiveModel::Name.new(self, self.parent)
		else
			super
		end
	end
	
	embedded_in :invoice

# Define routes with the embedded document as a nested resource
resources :invoices do
	resources :items
end

# if you decide that the controller should also use namespaces, place the __items_controller__ inside an __invoices__ folder and use:
resources :invoices do
	resources :items, :module => :invoices
end

Rake tasks

Todo

Known issues

Credits

Copyright (c) 2011 Alexandre Angelim, released under the MIT license.