Module: Mongoid::DocumentInclusion::ClassMethods
- Defined in:
- lib/mongoid-included/document_inclusion.rb
Instance Method Summary collapse
-
#included_in(relation_name, args = {}) ⇒ Object
Facade for Mongoid::Relations::Macros.embeded_in.
-
#includes_many(relation_name, args = {}) ⇒ Object
Facade for Mongoid::Relations::Macros.embeds_many.
-
#includes_one(relation_name, args = {}) ⇒ Object
Facade for Mongoid::Relations::Macros.embeds_one.
Instance Method Details
#included_in(relation_name, args = {}) ⇒ Object
Facade for Mongoid::Relations::Macros.embeded_in
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mongoid-included/document_inclusion.rb', line 35 def included_in(relation_name, args = {}) @skip_path_pluralization = args.delete(:skip_path_pluralization) relation_klass = if args[:class_name] infer_klass(args[:class_name]) else infer_klass(relation_name) end raise NotMongoidDocument, "Parent must be Mongoid::Document" unless has_mongoid? self.parent raise DocumentAlreadyIncluded, "Document already included" if (included_by | [ relation_klass ]).size > 1 relation_name, args self.included_by |= [ relation_klass ] self.extend ActiveModel::Naming _overwrite_model_name end |
#includes_many(relation_name, args = {}) ⇒ Object
Facade for Mongoid::Relations::Macros.embeds_many
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mongoid-included/document_inclusion.rb', line 57 def includes_many(relation_name, args = {}) relation_klass = if args[:class_name] infer_klass(args[:class_name]) else klass_to_include(relation_name) end verify_inclusion_dependencies(relation_klass) self.including_many |= [ relation_klass ] relation_name, args.merge(:class_name => relation_klass.name ) end |
#includes_one(relation_name, args = {}) ⇒ Object
Facade for Mongoid::Relations::Macros.embeds_one
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/mongoid-included/document_inclusion.rb', line 74 def includes_one(relation_name, args = {}) relation_klass = if args[:class_name] infer_klass(args[:class_name]) else klass_to_include(relation_name) end verify_inclusion_dependencies(relation_klass) self.including_one |= [ relation_klass ] relation_name, args.merge(:class_name => relation_klass.name ) end |