Module: Mongoid::Association::Nested::Buildable
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/mongoid/association/nested/nested_buildable.rb |
Overview
Mixin module containing common functionality used to perform #accepts_nested_attributes_for attribute assignment on associations.
Instance Attribute Summary
-
#allow_destroy? ⇒ true | false
readonly
Determines if destroys are allowed for this document.
- #association rw
- #attributes rw
- #existing rw
- #options rw
-
#update_only? ⇒ true | false
readonly
Determines if only updates can occur.
Instance Method Summary
-
#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.
-
#delete_id(hash) ⇒ Object
private
Deletes the id key from the given hash.
-
#extract_id(hash) ⇒ Object
private
Get the id attribute from the given hash, whether it’s prefixed with an underscore or is a symbol.
Instance Attribute Details
#allow_destroy? ⇒ true
| false
(readonly)
Determines if destroys are allowed for this document.
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 21
def allow_destroy? [:allow_destroy] || false end
#association (rw)
[ GitHub ]# File 'lib/mongoid/association/nested/nested_buildable.rb', line 13
attr_accessor :attributes, :existing, :association, :
#attributes (rw)
[ GitHub ]# File 'lib/mongoid/association/nested/nested_buildable.rb', line 13
attr_accessor :attributes, :existing, :association, :
#existing (rw)
[ GitHub ]# File 'lib/mongoid/association/nested/nested_buildable.rb', line 13
attr_accessor :attributes, :existing, :association, :
#options (rw)
[ GitHub ]# File 'lib/mongoid/association/nested/nested_buildable.rb', line 13
attr_accessor :attributes, :existing, :association, :
#update_only? ⇒ true
| false
(readonly)
Determines if only updates can occur. Only valid for one-to-one associations.
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 52
def update_only? [:update_only] || false end
Instance Method Details
#convert_id(klass, id) ⇒ BSON::ObjectId | String | Object
Convert an id to its appropriate type.
#delete_id(hash) ⇒ Object
(private)
Deletes the id key from the given hash.
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 92
def delete_id(hash) hash.delete('_id') || hash.delete(:_id) || hash.delete('id') || hash.delete(:id) end
#extract_id(hash) ⇒ Object
(private)
Get the id attribute from the given hash, whether it’s prefixed with an underscore or is a symbol.
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 80
def extract_id(hash) hash['_id'] || hash[:_id] || hash['id'] || hash[:id] end
#reject?(document, attrs) ⇒ true
| false
Returns the reject if option defined with the macro.
# File 'lib/mongoid/association/nested/nested_buildable.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