Module: MongoMapper::Plugins::Persistence::ClassMethods

Defined in:
lib/mongo_mapper/plugins/persistence.rb

Defined Under Namespace

Classes: Unsupported

Instance Method Summary collapse

Instance Method Details

#collectionObject



66
67
68
69
# File 'lib/mongo_mapper/plugins/persistence.rb', line 66

def collection
  not_supported_by_embedded
  database.collection(collection_name)
end

#collection_nameObject



61
62
63
64
# File 'lib/mongo_mapper/plugins/persistence.rb', line 61

def collection_name
  not_supported_by_embedded
  @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)
  not_supported_by_embedded
  if mongo_connection.nil?
    @connection ||= MongoMapper.connection
  else
    @connection = mongo_connection
  end
  @connection
end

#databaseObject



37
38
39
40
41
42
43
44
# File 'lib/mongo_mapper/plugins/persistence.rb', line 37

def database
  not_supported_by_embedded
  if database_name.nil?
    MongoMapper.database
  else
    connection.db(database_name)
  end
end

#database_nameObject



32
33
34
35
# File 'lib/mongo_mapper/plugins/persistence.rb', line 32

def database_name
  not_supported_by_embedded
  @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)
  not_supported_by_embedded
  @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)
  not_supported_by_embedded
  @database_name = name
end

#slave_collectionObject



71
72
73
74
# File 'lib/mongo_mapper/plugins/persistence.rb', line 71

def slave_collection
  not_supported_by_embedded
  slave_database.collection(collection_name)
end

#slave_connectionObject



18
19
20
21
22
23
24
25
# File 'lib/mongo_mapper/plugins/persistence.rb', line 18

def slave_connection
  not_supported_by_embedded
  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_databaseObject



46
47
48
49
50
51
52
53
54
# File 'lib/mongo_mapper/plugins/persistence.rb', line 46

def slave_database
  not_supported_by_embedded
  conn = slave_connection
  if database_name.nil?
    conn.db(MongoMapper.database.name)
  else
    conn.db(database_name)
  end
end