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

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

Instance Method Summary collapse

Instance Method Details

#collectionObject



45
46
47
48
# File 'lib/mongo_mapper/plugins/persistence.rb', line 45

def collection
  assert_supported
  database.collection(collection_name)
end

#collection_nameObject



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

def collection_name
  assert_supported
  @collection_name ||= self.to_s.tableize.gsub(/\//, '.')
end

#connection(mongo_connection = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/mongo_mapper/plugins/persistence.rb', line 6

def connection(mongo_connection=nil)
  assert_supported
  if mongo_connection.nil?
    @connection ||= MongoMapper.connection
  else
    @connection = mongo_connection
  end
  @connection
end

#databaseObject



26
27
28
29
30
31
32
33
# File 'lib/mongo_mapper/plugins/persistence.rb', line 26

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

#database_nameObject



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

def database_name
  assert_supported
  @database_name
end

#set_collection_name(name) ⇒ Object



35
36
37
38
# File 'lib/mongo_mapper/plugins/persistence.rb', line 35

def set_collection_name(name)
  assert_supported
  @collection_name = name
end

#set_database_name(name) ⇒ Object



16
17
18
19
# File 'lib/mongo_mapper/plugins/persistence.rb', line 16

def set_database_name(name)
  assert_supported
  @database_name = name
end