mongo_collection 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mongo_collection.rb +55 -0
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59477e2577882e80ced806a6da525cc37b04487b
|
4
|
+
data.tar.gz: dfaf52e51e3cf78818e0432d3fcf2b92484985bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7472c422fee878d00f2180b856ad750d9d3309694ba66fb6b3d4e825c137a0e14e80b790844f47892a87f0a7d620493d899c6d637a8bf0403c60c84378f3c7d2
|
7
|
+
data.tar.gz: a86ca34971a2622a2d61da11dfa569c1dfc527dbadf31f7f2aeda9e53fc7ada9ab706ba3194c47d911cc1c3060e962c5c07ac6af94c07c0f063d7ef0ca5f7ffe
|
data/lib/mongo_collection.rb
CHANGED
@@ -2,6 +2,61 @@ module MongoCollection
|
|
2
2
|
def self.included base
|
3
3
|
base.extend ClassMethods
|
4
4
|
end
|
5
|
+
|
6
|
+
def blank?
|
7
|
+
respond_to?(:empty?) ? !!empty? : !self
|
8
|
+
end
|
9
|
+
|
10
|
+
class DB
|
11
|
+
class << self
|
12
|
+
attr_accessor :client, :db
|
13
|
+
end
|
14
|
+
|
15
|
+
@config = { :addr => "localhost", :database => "my_database" }
|
16
|
+
@valid_config_keys = @config.keys
|
17
|
+
|
18
|
+
# Configure through hash
|
19
|
+
def self.configure(opts = {})
|
20
|
+
opts.each { |k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym }
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.configure_with(path_to_yaml_file)
|
24
|
+
begin
|
25
|
+
config = YAML::load(IO.read(path_to_yaml_file))
|
26
|
+
rescue => e
|
27
|
+
raise "YAML configuration file couldn't be found: #{e}"
|
28
|
+
end
|
29
|
+
configure(config)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.[](key)
|
33
|
+
return DB.client[key]
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.establish_connection
|
37
|
+
Mongo::Logger.logger.level = ::Logger::FATAL
|
38
|
+
DB.client = Mongo::Client.new([@config[:addr]], :database => @config[:database])
|
39
|
+
DB.db = @client.database
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.close_connection
|
43
|
+
DB.client.close
|
44
|
+
DB.db = nil
|
45
|
+
end
|
46
|
+
def self.collections
|
47
|
+
DB.db.collections
|
48
|
+
end
|
49
|
+
def self.info
|
50
|
+
self.db.command(dbstats: 1).first
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.hash
|
54
|
+
md5 = Digest::MD5.new
|
55
|
+
md5 << DB.collections.map{|x| x.count}.pack("C*")
|
56
|
+
md5.hexdigest
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
5
60
|
class MongoCollectionProxy
|
6
61
|
def initialize(collection, klass)
|
7
62
|
@class = klass
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_collection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Malay
|
@@ -9,7 +9,27 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2017-12-01 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mongo
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.4'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.4.3
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.4'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.4.3
|
13
33
|
description: A simple ORM for mongodb
|
14
34
|
email: flagmansupport@gmail.com
|
15
35
|
executables: []
|