Class: Mongoid::Relations::NestedBuilder
- Inherits:
-
Object
- Object
- Mongoid::Relations::NestedBuilder
- Defined in:
- lib/mongoid/relations/nested_builder.rb
Overview
This is the superclass for builders that are in charge of handling creation, deletion, and updates of documents through that ever so lovely #accepts_nested_attributes_for.
Direct Known Subclasses
Builders::NestedAttributes::Many, Builders::NestedAttributes::One
Instance Attribute Summary (collapse)
-
- (Object) attributes
Returns the value of attribute attributes.
-
- (Object) existing
Returns the value of attribute existing.
-
- (Object) metadata
Returns the value of attribute metadata.
-
- (Object) options
Returns the value of attribute options.
Instance Method Summary (collapse)
-
- (true, false) allow_destroy?
Determines if destroys are allowed for this document.
-
- (BSON::ObjectId, ...) convert_id(klass, id)
Convert an id to its appropriate type.
-
- (true, false) reject?(document, attrs)
Returns the reject if option defined with the macro.
-
- (true, false) update_only?
Determines if only updates can occur.
Instance Attribute Details
- (Object) attributes
Returns the value of attribute attributes
9 10 11 |
# File 'lib/mongoid/relations/nested_builder.rb', line 9 def attributes @attributes end |
- (Object) existing
Returns the value of attribute existing
9 10 11 |
# File 'lib/mongoid/relations/nested_builder.rb', line 9 def existing @existing end |
- (Object) metadata
Returns the value of attribute metadata
9 10 11 |
# File 'lib/mongoid/relations/nested_builder.rb', line 9 def @metadata end |
- (Object) options
Returns the value of attribute options
9 10 11 |
# File 'lib/mongoid/relations/nested_builder.rb', line 9 def @options end |
Instance Method Details
- (true, false) allow_destroy?
Determines if destroys are allowed for this document.
19 20 21 |
# File 'lib/mongoid/relations/nested_builder.rb', line 19 def allow_destroy? [:allow_destroy] || false end |
- (BSON::ObjectId, ...) convert_id(klass, id)
Durran: Move this into a common reusable place.
Convert an id to its appropriate type.
71 72 73 |
# File 'lib/mongoid/relations/nested_builder.rb', line 71 def convert_id(klass, id) klass.using_object_ids? ? BSON::ObjectId.mongoize(id) : id end |
- (true, false) reject?(document, attrs)
Returns the reject if option defined with the macro.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mongoid/relations/nested_builder.rb', line 34 def reject?(document, attrs) case callback = [:reject_if] when Symbol document.method(callback).arity == 0 ? document.send(callback) : document.send(callback, attrs) when Proc callback.call(attrs) else false end end |
- (true, false) update_only?
Determines if only updates can occur. Only valid for one-to-one relations.
54 55 56 |
# File 'lib/mongoid/relations/nested_builder.rb', line 54 def update_only? [:update_only] || false end |