Module: MongoMapper::Plugins::Persistence::ClassMethods
- Defined in:
- lib/mongo_mapper/plugins/persistence.rb
Defined Under Namespace
Classes: Unsupported
Instance Method Summary collapse
- #collection ⇒ Object
- #collection_name ⇒ Object
- #connection(mongo_connection = nil) ⇒ Object
- #database ⇒ Object
- #database_name ⇒ Object
- #set_collection_name(name) ⇒ Object
- #set_database_name(name) ⇒ Object
- #slave_collection ⇒ Object
- #slave_connection ⇒ Object
- #slave_database ⇒ Object
Instance Method Details
#collection ⇒ Object
66 67 68 69 |
# File 'lib/mongo_mapper/plugins/persistence.rb', line 66 def collection database.collection(collection_name) end |
#collection_name ⇒ Object
61 62 63 64 |
# File 'lib/mongo_mapper/plugins/persistence.rb', line 61 def collection_name @collection_name ||= self.to_s.tableize.gsub(/\//, '.') end |
#connection(mongo_connection = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/mongo_mapper/plugins/persistence.rb', line 8 def connection(mongo_connection=nil) if mongo_connection.nil? @connection ||= MongoMapper.connection else @connection = mongo_connection end @connection end |
#database ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/mongo_mapper/plugins/persistence.rb', line 37 def database if database_name.nil? MongoMapper.database else connection.db(database_name) end end |
#database_name ⇒ Object
32 33 34 35 |
# File 'lib/mongo_mapper/plugins/persistence.rb', line 32 def database_name @database_name end |
#set_collection_name(name) ⇒ Object
56 57 58 59 |
# File 'lib/mongo_mapper/plugins/persistence.rb', line 56 def set_collection_name(name) @collection_name = name end |
#set_database_name(name) ⇒ Object
27 28 29 30 |
# File 'lib/mongo_mapper/plugins/persistence.rb', line 27 def set_database_name(name) @database_name = name end |
#slave_collection ⇒ Object
71 72 73 74 |
# File 'lib/mongo_mapper/plugins/persistence.rb', line 71 def slave_collection slave_database.collection(collection_name) end |
#slave_connection ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/mongo_mapper/plugins/persistence.rb', line 18 def slave_connection raise "Slave connections have not been configured" if MongoMapper.slave_connections.empty? @slave_idx ||= 0 conn = MongoMapper.slave_connections[@slave_idx] increment_slave_idx conn end |
#slave_database ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/mongo_mapper/plugins/persistence.rb', line 46 def slave_database conn = slave_connection if database_name.nil? conn.db(MongoMapper.database.name) else conn.db(database_name) end end |