volt-mongo 0.0.2 → 0.1.0
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/VERSION +1 -1
- data/app/mongo/lib/mongo_adaptor_client.rb +5 -0
- data/app/mongo/lib/mongo_adaptor_server.rb +41 -7
- data/volt-mongo.gemspec +0 -2
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a143e4b5a3dd0d8ed8fa9733f7f0d8c2130aa6b9
|
4
|
+
data.tar.gz: b322267be712e962689a1492817109bea47fdd13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb0f274044351a4adb16b2216fe2e36a7abc562e49940eb9ca083f8fdc21354045918f7a0fe920fb208a4d49748c73ab83cd0ac9c988f495ae9a43d699f10bf4
|
7
|
+
data.tar.gz: 4b9836aaa072833e975c660f94b995bfb9bc92a1c37b1fc444713391363d878b4638abed7e99e9c0d66a8964656cfd53e4bff01df433a3f797435af3bf0330d0
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -14,12 +14,17 @@ module Volt
|
|
14
14
|
def order(sort)
|
15
15
|
add_query_part(:sort, sort)
|
16
16
|
end
|
17
|
+
|
18
|
+
# def count
|
19
|
+
# add_query_part(:count).then
|
20
|
+
# end
|
17
21
|
end
|
18
22
|
|
19
23
|
# Due to the way define_method works, we need to remove the generated
|
20
24
|
# methods from data_store_methods before we over-ride them.
|
21
25
|
Volt::Persistors::ArrayStore.send(:remove_method, :where)
|
22
26
|
Volt::Persistors::ArrayStore.send(:remove_method, :order)
|
27
|
+
# Volt::Persistors::ArrayStore.send(:remove_method, :count)
|
23
28
|
|
24
29
|
# include mongo's methods on ArrayStore
|
25
30
|
Volt::Persistors::ArrayStore.send(:include, MongoArrayStore)
|
@@ -1,11 +1,38 @@
|
|
1
1
|
require 'mongo'
|
2
2
|
|
3
|
+
# We need to be able to deeply stringify keys for mongo
|
4
|
+
class Hash
|
5
|
+
def nested_stringify_keys
|
6
|
+
self.stringify_keys.map do |key, value|
|
7
|
+
if value.is_a?(Hash)
|
8
|
+
value = value.nested_stringify_keys
|
9
|
+
end
|
10
|
+
|
11
|
+
[key, value]
|
12
|
+
end.to_h
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
3
16
|
module Volt
|
4
17
|
class DataStore
|
5
18
|
class MongoAdaptorServer < BaseAdaptorServer
|
6
19
|
attr_reader :db, :mongo_db
|
7
20
|
|
8
|
-
|
21
|
+
# check if the database can be connected to.
|
22
|
+
# @return Boolean
|
23
|
+
def connected?
|
24
|
+
begin
|
25
|
+
db
|
26
|
+
|
27
|
+
true
|
28
|
+
rescue ::Mongo::ConnectionFailure => e
|
29
|
+
false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def db
|
34
|
+
return @db if @db
|
35
|
+
|
9
36
|
if Volt.config.db_uri.present?
|
10
37
|
@mongo_db ||= ::Mongo::MongoClient.from_uri(Volt.config.db_uri)
|
11
38
|
@db ||= @mongo_db.db(Volt.config.db_uri.split('/').last || Volt.config.db_name)
|
@@ -13,26 +40,28 @@ module Volt
|
|
13
40
|
@mongo_db ||= ::Mongo::MongoClient.new(Volt.config.db_host, Volt.config.db_port)
|
14
41
|
@db ||= @mongo_db.db(Volt.config.db_name)
|
15
42
|
end
|
43
|
+
|
44
|
+
@db
|
16
45
|
end
|
17
46
|
|
18
47
|
def insert(collection, values)
|
19
|
-
|
48
|
+
db[collection].insert(values)
|
20
49
|
end
|
21
50
|
|
22
51
|
def update(collection, values)
|
23
|
-
values = values.
|
52
|
+
values = values.nested_stringify_keys
|
24
53
|
|
25
54
|
to_mongo_id!(values)
|
26
55
|
# TODO: Seems mongo is dumb and doesn't let you upsert with custom id's
|
27
56
|
begin
|
28
|
-
|
57
|
+
db[collection].insert(values)
|
29
58
|
rescue ::Mongo::OperationFailure => error
|
30
59
|
# Really mongo client?
|
31
60
|
if error.message[/^11000[:]/]
|
32
61
|
# Update because the id already exists
|
33
62
|
update_values = values.dup
|
34
63
|
id = update_values.delete('_id')
|
35
|
-
|
64
|
+
db[collection].update({ '_id' => id }, update_values)
|
36
65
|
else
|
37
66
|
return { error: error.message }
|
38
67
|
end
|
@@ -44,7 +73,7 @@ module Volt
|
|
44
73
|
def query(collection, query)
|
45
74
|
allowed_methods = %w(find skip limit count)
|
46
75
|
|
47
|
-
result =
|
76
|
+
result = db[collection]
|
48
77
|
|
49
78
|
query.each do |query_part|
|
50
79
|
method_name, *args = query_part
|
@@ -86,7 +115,12 @@ module Volt
|
|
86
115
|
query['_id'] = query.delete('id')
|
87
116
|
end
|
88
117
|
|
89
|
-
|
118
|
+
db[collection].remove(query)
|
119
|
+
end
|
120
|
+
|
121
|
+
# remove the collection entirely
|
122
|
+
def drop_collection(collection)
|
123
|
+
db.drop_collection(collection)
|
90
124
|
end
|
91
125
|
|
92
126
|
def drop_database
|
data/volt-mongo.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: volt-mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Stout
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05
|
11
|
+
date: 2015-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.9.0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: volt
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.9.2
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 0.9.2
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rake
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|