class MongoCollection::DB
Attributes
client[RW]
db[RW]
Public Class Methods
[](key)
click to toggle source
# File lib/mongo_collection.rb, line 32 def self.[](key) return DB.client[key] end
close_connection()
click to toggle source
# File lib/mongo_collection.rb, line 42 def self.close_connection DB.client.close DB.db = nil end
collections()
click to toggle source
# File lib/mongo_collection.rb, line 46 def self.collections DB.db.collections end
configure(opts = {})
click to toggle source
Configure through hash
# File lib/mongo_collection.rb, line 19 def self.configure(opts = {}) opts.each { |k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym } end
configure_with(path_to_yaml_file)
click to toggle source
# File lib/mongo_collection.rb, line 23 def self.configure_with(path_to_yaml_file) begin config = YAML::load(IO.read(path_to_yaml_file)) rescue => e raise "YAML configuration file couldn't be found: #{e}" end configure(config) end
establish_connection()
click to toggle source
# File lib/mongo_collection.rb, line 36 def self.establish_connection Mongo::Logger.logger.level = ::Logger::FATAL DB.client = Mongo::Client.new([@config[:addr]], :database => @config[:database]) DB.db = @client.database end
hash()
click to toggle source
# File lib/mongo_collection.rb, line 53 def self.hash md5 = Digest::MD5.new md5 << DB.collections.map{|x| x.count}.pack("C*") md5.hexdigest end
info()
click to toggle source
# File lib/mongo_collection.rb, line 49 def self.info self.db.command(dbstats: 1).first end