mongorilla 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -1
- data/lib/mongorilla/collection.rb +10 -1
- metadata +13 -13
data/README.rdoc
CHANGED
@@ -56,7 +56,8 @@ mongorilla accept single server or Master/Slave or Replica Set
|
|
56
56
|
|
57
57
|
=== syntax
|
58
58
|
1. Connect Server below statement when boot application
|
59
|
-
Mongorilla::Collection.build("/var/www/mongo_config.yml")
|
59
|
+
Mongorilla::Collection.build("/var/www/mongo_config.yml",Logger.new("logfile.log"))
|
60
|
+
logger is option. if logger does not exist,Mongorilla does not output log.
|
60
61
|
2. create document class and define constant class name + Fields with document fields and include Mongorilla::Document.
|
61
62
|
class Class
|
62
63
|
ClassNameFields = [:_id,...]
|
@@ -6,6 +6,7 @@ module Mongorilla
|
|
6
6
|
@@slaves = nil
|
7
7
|
@@slave_index = 0
|
8
8
|
@@config = nil
|
9
|
+
@@loger = nil
|
9
10
|
|
10
11
|
def self.master
|
11
12
|
@@master
|
@@ -23,10 +24,11 @@ module Mongorilla
|
|
23
24
|
@@config = YAML.load(File.read(path))
|
24
25
|
end
|
25
26
|
|
26
|
-
def self.build(path=File.expand_path("../config.yml",__FILE__))
|
27
|
+
def self.build(path=File.expand_path("../config.yml",__FILE__),logger=nil)
|
27
28
|
load_config(path)
|
28
29
|
@@config["max_retries"] ||= 10
|
29
30
|
@@config["meantime"] ||= 0.5
|
31
|
+
@@loger = logger
|
30
32
|
if @@config["hosts"]
|
31
33
|
@@master = Mongo::ReplSetConnection.new(*@@config["hosts"]).db(@@config["database"])
|
32
34
|
elsif @@config["slaves"]
|
@@ -67,6 +69,7 @@ module Mongorilla
|
|
67
69
|
end
|
68
70
|
|
69
71
|
def count(cond={},opt={})
|
72
|
+
@@loger.info("count cond:#{cond.inspect} opt:#{opt.inspect}") if @@loger
|
70
73
|
find(cond,opt).count
|
71
74
|
end
|
72
75
|
|
@@ -78,6 +81,7 @@ module Mongorilla
|
|
78
81
|
opt[:read] = :primary
|
79
82
|
end
|
80
83
|
rescue_connection_failure do
|
84
|
+
@@loger.info("find(master) cond:#{cond.inspect} opt:#{opt.inspect}") if @@loger
|
81
85
|
w_col.find(cond,opt)
|
82
86
|
end
|
83
87
|
else
|
@@ -86,9 +90,11 @@ module Mongorilla
|
|
86
90
|
end
|
87
91
|
begin
|
88
92
|
rescue_connection_failure do
|
93
|
+
@@loger.info("find(secondary) cond:#{cond.inspect} opt:#{opt.inspect}") if @@loger
|
89
94
|
r_col.find(cond,opt)
|
90
95
|
end
|
91
96
|
rescue
|
97
|
+
@@loger.info("find(master) cond:#{cond.inspect} opt:#{opt.inspect}") if @@loger
|
92
98
|
w_col.find(cond,opt)
|
93
99
|
end
|
94
100
|
end
|
@@ -96,12 +102,14 @@ module Mongorilla
|
|
96
102
|
|
97
103
|
def insert(data,opt={})
|
98
104
|
rescue_connection_failure do
|
105
|
+
@@loger.info("insert data:#{data.inspect} opt:#{opt.inspect}") if @@loger
|
99
106
|
w_col.insert(data,opt)
|
100
107
|
end
|
101
108
|
end
|
102
109
|
|
103
110
|
def update(cond,data,opt)
|
104
111
|
rescue_connection_failure do
|
112
|
+
@@loger.info("update cond:#{cond.inspect} data:#{data.inspect} opt:#{opt.inspect}") if @@loger
|
105
113
|
w_col.update(cond,data,opt)
|
106
114
|
end
|
107
115
|
end
|
@@ -113,6 +121,7 @@ module Mongorilla
|
|
113
121
|
cond = {:_id => cond}
|
114
122
|
end
|
115
123
|
rescue_connection_failure do
|
124
|
+
@@loger.info("remove cond:#{cond.inspect} opt:#{opt.inspect}") if @@loger
|
116
125
|
w_col.remove(cond,opt)
|
117
126
|
end
|
118
127
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongorilla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongo
|
16
|
-
requirement: &
|
16
|
+
requirement: &24528560 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *24528560
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &24527180 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.3.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *24527180
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &24567860 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.0.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *24567860
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &24564400 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.6.4
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *24564400
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rcov
|
60
|
-
requirement: &
|
60
|
+
requirement: &24577060 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *24577060
|
69
69
|
description: Small Object Document Mapper for Mongo. you can update atomic with condition
|
70
70
|
email: laten@nifty.com
|
71
71
|
executables: []
|
@@ -94,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
segments:
|
96
96
|
- 0
|
97
|
-
hash:
|
97
|
+
hash: 3892581784407643389
|
98
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
99
|
none: false
|
100
100
|
requirements:
|