Module: Mongoid::Association::Nested::Buildable
Overview
Mixin module containing common functionality used to perform #accepts_nested_attributes_for attribute assignment on associations.
Instance Attribute Summary collapse
-
#association ⇒ Object
Returns the value of attribute association.
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#existing ⇒ Object
Returns the value of attribute existing.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#allow_destroy? ⇒ true | false
Determines if destroys are allowed for this document.
-
#convert_id(klass, id) ⇒ BSON::ObjectId | String | Object
Convert an id to its appropriate type.
-
#reject?(document, attrs) ⇒ true | false
Returns the reject if option defined with the macro.
-
#update_only? ⇒ true | false
Determines if only updates can occur.
Instance Attribute Details
#association ⇒ Object
Returns the value of attribute association.
10 11 12 |
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 10 def association @association end |
#attributes ⇒ Object
Returns the value of attribute attributes.
10 11 12 |
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 10 def attributes @attributes end |
#existing ⇒ Object
Returns the value of attribute existing.
10 11 12 |
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 10 def existing @existing end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 10 def end |
Instance Method Details
#allow_destroy? ⇒ true | false
Determines if destroys are allowed for this document.
18 19 20 |
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 18 def allow_destroy? [:allow_destroy] || false end |
#convert_id(klass, id) ⇒ BSON::ObjectId | String | Object
Convert an id to its appropriate type.
Ids arriving from a form are always scalars. A Hash or an Array here means the parameters were crafted, and letting one through would turn the id into a query operator, so they are rejected.
72 73 74 75 76 77 78 |
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 72 def convert_id(klass, id) raise Errors::DocumentNotFound.new(klass, id) if id.is_a?(::Hash) || id.is_a?(::Array) klass.using_object_ids? ? BSON::ObjectId.mongoize(id) : id rescue BSON::Error raise Errors::DocumentNotFound.new(klass, id) end |
#reject?(document, attrs) ⇒ true | false
Returns the reject if option defined with the macro.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 31 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 |
#update_only? ⇒ true | false
Determines if only updates can occur. Only valid for one-to-one associations.
49 50 51 |
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 49 def update_only? [:update_only] || false end |