volt-mongo 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6de39d6ea21dd7173c966c2bd36951928819fd4f
4
- data.tar.gz: 9c5b9b5185fa9c3dc6973e23a646f3b3fef9f692
3
+ metadata.gz: a143e4b5a3dd0d8ed8fa9733f7f0d8c2130aa6b9
4
+ data.tar.gz: b322267be712e962689a1492817109bea47fdd13
5
5
  SHA512:
6
- metadata.gz: 5fd5f4f6de16626eb700f0b429a1a8c05ae16196ed0023e134e7671c67386a793b7670cc4df9e7842221a6153a9d5b38ad4e1b2211ebbca5862b4b001602a04e
7
- data.tar.gz: f852df5a6fd80cfcfeab530290c4f3e017c8d52ee80728f7429eb96d0ede45109e98776dbaf254799207899e90688176a5a4ca9b63a48b9a86fca550ee754e1d
6
+ metadata.gz: fb0f274044351a4adb16b2216fe2e36a7abc562e49940eb9ca083f8fdc21354045918f7a0fe920fb208a4d49748c73ab83cd0ac9c988f495ae9a43d699f10bf4
7
+ data.tar.gz: 4b9836aaa072833e975c660f94b995bfb9bc92a1c37b1fc444713391363d878b4638abed7e99e9c0d66a8964656cfd53e4bff01df433a3f797435af3bf0330d0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
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
- def initialize
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
- @db[collection].insert(values)
48
+ db[collection].insert(values)
20
49
  end
21
50
 
22
51
  def update(collection, values)
23
- values = values.stringify_keys
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
- @db[collection].insert(values)
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
- @db[collection].update({ '_id' => id }, update_values)
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 = @db[collection]
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
- @db[collection].remove(query)
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
@@ -20,7 +20,5 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_dependency 'mongo', '~> 1.9.0'
23
-
24
- spec.add_development_dependency "volt", "~> 0.9.2"
25
23
  spec.add_development_dependency "rake"
26
24
  end
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.2
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-26 00:00:00.000000000 Z
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