Class: MongoBrowser::Models::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo_browser/models/database.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mongo_db) ⇒ Database

Returns a new instance of Database.



6
7
8
# File 'lib/mongo_browser/models/database.rb', line 6

def initialize(mongo_db)
  @mongo_db = mongo_db
end

Instance Attribute Details

#mongo_dbObject (readonly)

Returns the value of attribute mongo_db.



4
5
6
# File 'lib/mongo_browser/models/database.rb', line 4

def mongo_db
  @mongo_db
end

Instance Method Details

#collection(name) ⇒ Object



27
28
29
# File 'lib/mongo_browser/models/database.rb', line 27

def collection(name)
  Collection.new(mongo_db.collection(name))
end

#collection_namesObject



23
24
25
# File 'lib/mongo_browser/models/database.rb', line 23

def collection_names
  mongo_db.collection_names
end

#collectionsObject



31
32
33
# File 'lib/mongo_browser/models/database.rb', line 31

def collections
  collection_names.map { |name| collection(name) }
end

#countObject



15
16
17
# File 'lib/mongo_browser/models/database.rb', line 15

def count
  collections.count
end

#drop!Object



39
40
41
# File 'lib/mongo_browser/models/database.rb', line 39

def drop!
  mongo_db.connection.drop_database(self.name)
end

#nameObject Also known as: id



10
11
12
# File 'lib/mongo_browser/models/database.rb', line 10

def name
  mongo_db.name
end

#sizeObject



19
20
21
# File 'lib/mongo_browser/models/database.rb', line 19

def size
  info["sizeOnDisk"].to_i
end

#statsObject



35
36
37
# File 'lib/mongo_browser/models/database.rb', line 35

def stats
  mongo_db.stats
end