Class: MongoCollection::DB
- Inherits:
-
Object
- Object
- MongoCollection::DB
- Defined in:
- lib/mongo_collection.rb
Class Attribute Summary collapse
-
.client ⇒ Object
Returns the value of attribute client.
-
.db ⇒ Object
Returns the value of attribute db.
Class Method Summary collapse
- .[](key) ⇒ Object
- .close_connection ⇒ Object
- .collections ⇒ Object
-
.configure(opts = {}) ⇒ Object
Configure through hash.
- .configure_with(path_to_yaml_file) ⇒ Object
- .establish_connection ⇒ Object
- .hash ⇒ Object
- .info ⇒ Object
Class Attribute Details
.client ⇒ Object
Returns the value of attribute client.
12 13 14 |
# File 'lib/mongo_collection.rb', line 12 def client @client end |
.db ⇒ Object
Returns the value of attribute db.
12 13 14 |
# File 'lib/mongo_collection.rb', line 12 def db @db end |
Class Method Details
.[](key) ⇒ Object
32 33 34 |
# File 'lib/mongo_collection.rb', line 32 def self.[](key) return DB.client[key] end |
.close_connection ⇒ Object
42 43 44 45 |
# File 'lib/mongo_collection.rb', line 42 def self.close_connection DB.client.close DB.db = nil end |
.collections ⇒ Object
46 47 48 |
# File 'lib/mongo_collection.rb', line 46 def self.collections DB.db.collections end |
.configure(opts = {}) ⇒ Object
Configure through hash
19 20 21 |
# 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) ⇒ Object
23 24 25 26 27 28 29 30 |
# 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 ⇒ Object
36 37 38 39 40 |
# 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 ⇒ Object
53 54 55 56 57 |
# 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 ⇒ Object
49 50 51 |
# File 'lib/mongo_collection.rb', line 49 def self.info self.db.command(dbstats: 1).first end |