Class: Mongo::Sugar::Collection
- Inherits:
-
Delegator
- Object
- Delegator
- Mongo::Sugar::Collection
- Includes:
- Singleton
- Defined in:
- lib/mongo-sugar/collection.rb
Class Attribute Summary collapse
-
.store_in_options ⇒ Object
readonly
Returns the value of attribute store_in_options.
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
Class Method Summary collapse
Instance Method Summary collapse
- #__getobj__ ⇒ Object
- #__setobj__(store_in_options) ⇒ Object
-
#initialize(store_in = {}) ⇒ Collection
constructor
Instance methods.
Constructor Details
#initialize(store_in = {}) ⇒ Collection
Instance methods
31 32 33 |
# File 'lib/mongo-sugar/collection.rb', line 31 def initialize(store_in={}) __setobj__(self.class. || {}) end |
Class Attribute Details
.store_in_options ⇒ Object (readonly)
Returns the value of attribute store_in_options.
15 16 17 |
# File 'lib/mongo-sugar/collection.rb', line 15 def @store_in_options end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
8 9 10 |
# File 'lib/mongo-sugar/collection.rb', line 8 def database @database end |
Class Method Details
.database ⇒ Object
18 19 20 |
# File 'lib/mongo-sugar/collection.rb', line 18 def database self.instance.database end |
.store_in(options) ⇒ Object
22 23 24 |
# File 'lib/mongo-sugar/collection.rb', line 22 def store_in() @store_in_options = end |
Instance Method Details
#__getobj__ ⇒ Object
44 45 46 |
# File 'lib/mongo-sugar/collection.rb', line 44 def __getobj__ @collection end |
#__setobj__(store_in_options) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/mongo-sugar/collection.rb', line 35 def __setobj__() conn = .delete(:connection) || 'default' db = .delete(:database) coll = .delete(:collection) || self.class.name.delete(':').gsub(/(.)([A-Z])/,'\1_\2').downcase @database = Mongo::Sugar::Connection::Manager.database(conn, db) @collection = @database[coll] end |