Class: MongoRecord::Subobject
- Defined in:
- lib/mongo_record/subobject.rb
Overview
A MongoRecord::Subobject is an MongoRecord::Base subclass that disallows many operations. Subobjects are those that are contained within and saved with some other object.
Using MongoRecord::Subobject is completely optional.
As an example, say a Student object contains an Address. You might want to make Address a subclass of Subobject so that you don’t accidentally try to save an address to a collection by itself.
Class Method Summary collapse
-
.collection_name(coll_name) ⇒ Object
Subobjects ignore the collection name.
-
.count(*args) ⇒ Object
Disallow count.
-
.delete(id) ⇒ Object
Disallow delete.
-
.delete_all(conditions = nil) ⇒ Object
Disallow delete_all.
-
.destroy(id) ⇒ Object
Disallow destroy.
-
.destroy_all(conditions = nil) ⇒ Object
Disallow destroy_all.
-
.find(*args) ⇒ Object
Disallow find.
-
.remove ⇒ Object
Disallow delete.
Instance Method Summary collapse
-
#create ⇒ Object
Disallow create.
-
#delete ⇒ Object
(also: #remove)
Disallow delete and remove.
-
#id ⇒ Object
Subobjects do not have their own ids.
-
#id=(val) ⇒ Object
Subobjects do not have their own ids.
-
#new_record? ⇒ Boolean
Disallow new_record?.
-
#to_param ⇒ Object
to_param normally returns the id of an object.
-
#update ⇒ Object
Disallow udpate.
Methods inherited from Base
#==, arrays, #attributes_from_column_definition, belongs_to, collection, connection, connection=, create, #destroy, #eql?, field, field_names, find_by_mql, has_and_belongs_to_many, has_many, has_one, #hash, inherited, #initialize, instantiate, method_missing, mongo_ivar_names, #save, #save!, subobjects, #to_mongo_value, update, update_all, #update_attribute, #update_attributes, #update_attributes!
Constructor Details
This class inherits a constructor from MongoRecord::Base
Class Method Details
.collection_name(coll_name) ⇒ Object
Subobjects ignore the collection name.
35 36 |
# File 'lib/mongo_record/subobject.rb', line 35 def collection_name(coll_name) end |
.count(*args) ⇒ Object
Disallow count.
44 45 46 |
# File 'lib/mongo_record/subobject.rb', line 44 def count(*args) complain("counted") end |
.delete(id) ⇒ Object
Disallow delete.
49 50 51 |
# File 'lib/mongo_record/subobject.rb', line 49 def delete(id) complain("deleted") end |
.delete_all(conditions = nil) ⇒ Object
Disallow delete_all.
65 66 67 |
# File 'lib/mongo_record/subobject.rb', line 65 def delete_all(conditions=nil) complain("deleted") end |
.destroy(id) ⇒ Object
Disallow destroy.
55 56 57 |
# File 'lib/mongo_record/subobject.rb', line 55 def destroy(id) complain("destroyed") end |
.destroy_all(conditions = nil) ⇒ Object
Disallow destroy_all.
60 61 62 |
# File 'lib/mongo_record/subobject.rb', line 60 def destroy_all(conditions = nil) complain("destroyed") end |
.find(*args) ⇒ Object
Disallow find.
39 40 41 |
# File 'lib/mongo_record/subobject.rb', line 39 def find(*args) complain("found") end |
.remove ⇒ Object
Disallow delete.
52 53 54 |
# File 'lib/mongo_record/subobject.rb', line 52 def delete(id) complain("deleted") end |
Instance Method Details
#create ⇒ Object
Disallow create.
94 95 96 |
# File 'lib/mongo_record/subobject.rb', line 94 def create self.class.complain("created") end |
#delete ⇒ Object Also known as: remove
Disallow delete and remove.
104 105 106 |
# File 'lib/mongo_record/subobject.rb', line 104 def delete self.class.complain("deleted") end |
#id ⇒ Object
Subobjects do not have their own ids. You’ll get a deprecation warning if you call this outside of Rails.
84 |
# File 'lib/mongo_record/subobject.rb', line 84 def id; raise "Subobjects don't have ids"; end |
#id=(val) ⇒ Object
Subobjects do not have their own ids.
80 |
# File 'lib/mongo_record/subobject.rb', line 80 def id=(val); raise "Subobjects don't have ids"; end |
#new_record? ⇒ Boolean
Disallow new_record?
91 |
# File 'lib/mongo_record/subobject.rb', line 91 def new_record?; raise "Subobjects don't have ids"; end |
#to_param ⇒ Object
to_param normally returns the id of an object. Since subobjects don’t have ids, this is disallowed.
88 |
# File 'lib/mongo_record/subobject.rb', line 88 def to_param; raise "Subobjects don't have ids"; end |
#update ⇒ Object
Disallow udpate.
99 100 101 |
# File 'lib/mongo_record/subobject.rb', line 99 def update self.class.complain("updated") end |