mongorilla 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongorilla/collection.rb +7 -7
- data/lib/mongorilla/document.rb +10 -10
- metadata +12 -12
@@ -69,7 +69,7 @@ module Mongorilla
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def count(cond={},opt={})
|
72
|
-
@@loger.info("count cond:#{cond.inspect} opt:#{opt.inspect}") if @@loger
|
72
|
+
@@loger.info("count #{@name} cond:#{cond.inspect} opt:#{opt.inspect}") if @@loger
|
73
73
|
find(cond,opt).count
|
74
74
|
end
|
75
75
|
|
@@ -81,7 +81,7 @@ module Mongorilla
|
|
81
81
|
opt[:read] = :primary
|
82
82
|
end
|
83
83
|
rescue_connection_failure do
|
84
|
-
@@loger.info("find(master) cond:#{cond.inspect} opt:#{opt.inspect}") if @@loger
|
84
|
+
@@loger.info("find(master) #{@name} cond:#{cond.inspect} opt:#{opt.inspect}") if @@loger
|
85
85
|
w_col.find(cond,opt)
|
86
86
|
end
|
87
87
|
else
|
@@ -90,11 +90,11 @@ module Mongorilla
|
|
90
90
|
end
|
91
91
|
begin
|
92
92
|
rescue_connection_failure do
|
93
|
-
@@loger.info("find(secondary) cond:#{cond.inspect} opt:#{opt.inspect}") if @@loger
|
93
|
+
@@loger.info("find(secondary) #{@name} cond:#{cond.inspect} opt:#{opt.inspect}") if @@loger
|
94
94
|
r_col.find(cond,opt)
|
95
95
|
end
|
96
96
|
rescue
|
97
|
-
@@loger.info("find(master) cond:#{cond.inspect} opt:#{opt.inspect}") if @@loger
|
97
|
+
@@loger.info("find(master) #{@name} cond:#{cond.inspect} opt:#{opt.inspect}") if @@loger
|
98
98
|
w_col.find(cond,opt)
|
99
99
|
end
|
100
100
|
end
|
@@ -102,14 +102,14 @@ module Mongorilla
|
|
102
102
|
|
103
103
|
def insert(data,opt={})
|
104
104
|
rescue_connection_failure do
|
105
|
-
@@loger.info("insert data:#{data.inspect} opt:#{opt.inspect}") if @@loger
|
105
|
+
@@loger.info("insert #{@name} data:#{data.inspect} opt:#{opt.inspect}") if @@loger
|
106
106
|
w_col.insert(data,opt)
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
110
|
def update(cond,data,opt)
|
111
111
|
rescue_connection_failure do
|
112
|
-
@@loger.info("update cond:#{cond.inspect} data:#{data.inspect} opt:#{opt.inspect}") if @@loger
|
112
|
+
@@loger.info("update #{@name} cond:#{cond.inspect} data:#{data.inspect} opt:#{opt.inspect}") if @@loger
|
113
113
|
w_col.update(cond,data,opt)
|
114
114
|
end
|
115
115
|
end
|
@@ -121,7 +121,7 @@ module Mongorilla
|
|
121
121
|
cond = {:_id => cond}
|
122
122
|
end
|
123
123
|
rescue_connection_failure do
|
124
|
-
@@loger.info("remove cond:#{cond.inspect} opt:#{opt.inspect}") if @@loger
|
124
|
+
@@loger.info("remove #{@name} cond:#{cond.inspect} opt:#{opt.inspect}") if @@loger
|
125
125
|
w_col.remove(cond,opt)
|
126
126
|
end
|
127
127
|
end
|
data/lib/mongorilla/document.rb
CHANGED
@@ -36,7 +36,7 @@ module Mongorilla
|
|
36
36
|
end
|
37
37
|
alias_method :id,:_id
|
38
38
|
col_name = pluralize(c.to_s)
|
39
|
-
|
39
|
+
c.instance_variable_set("@col",Collection.new(col_name))
|
40
40
|
|
41
41
|
def initialize(doc)
|
42
42
|
@orig = doc.dup
|
@@ -138,7 +138,7 @@ module Mongorilla
|
|
138
138
|
opt[:safe] = true if [SYNC,RELOAD].include?(mode)
|
139
139
|
cond.merge!({"_id" => @doc["_id"]})
|
140
140
|
if @changes
|
141
|
-
ret =
|
141
|
+
ret = self.class.collection.update(cond,@changes,opt)
|
142
142
|
if opt[:safe] && ret["n"] != 1
|
143
143
|
reset
|
144
144
|
return false
|
@@ -163,19 +163,19 @@ module Mongorilla
|
|
163
163
|
|
164
164
|
def reload
|
165
165
|
@changes={}
|
166
|
-
@doc =
|
166
|
+
@doc = self.class.collection.find_one(id,:master => true)
|
167
167
|
@orig = @doc.dup
|
168
168
|
end
|
169
169
|
|
170
170
|
def c.collection
|
171
|
-
|
171
|
+
@col
|
172
172
|
end
|
173
173
|
|
174
174
|
def c.create(data,opt={})
|
175
175
|
if opt == {}
|
176
176
|
opt[:safe] = true
|
177
177
|
end
|
178
|
-
ret =
|
178
|
+
ret = @col.insert(data,opt)
|
179
179
|
if opt[:safe] == true
|
180
180
|
if ret.is_a? Array
|
181
181
|
ret.map{|uid| find(uid,:master=>true)}
|
@@ -186,7 +186,7 @@ module Mongorilla
|
|
186
186
|
end
|
187
187
|
|
188
188
|
def c.find_one(cond,opt={})
|
189
|
-
ret =
|
189
|
+
ret = @col.find_one(cond,opt)
|
190
190
|
if ret
|
191
191
|
return self.new(ret)
|
192
192
|
else
|
@@ -195,25 +195,25 @@ module Mongorilla
|
|
195
195
|
end
|
196
196
|
|
197
197
|
def c.count(cond={},opt={})
|
198
|
-
|
198
|
+
@col.count(cond,opt)
|
199
199
|
end
|
200
200
|
|
201
201
|
def c.find(cond={},opt={})
|
202
202
|
if !cond.is_a? Hash
|
203
203
|
find_one(cond,opt)
|
204
204
|
else
|
205
|
-
ret =
|
205
|
+
ret = @col.find(cond,opt)
|
206
206
|
return [] if ret.count == 0
|
207
207
|
ret.map{|r| self.new(r)}
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
211
211
|
def c.update(cond,data,opt={})
|
212
|
-
|
212
|
+
@col.update(cond,data,opt)
|
213
213
|
end
|
214
214
|
|
215
215
|
def c.remove(cond={},opt={})
|
216
|
-
|
216
|
+
@col.remove(cond,opt)
|
217
217
|
end
|
218
218
|
end
|
219
219
|
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.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ 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: &13628080 !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: *13628080
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &13626300 !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: *13626300
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &13624320 !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: *13624320
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &13635240 !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: *13635240
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rcov
|
60
|
-
requirement: &
|
60
|
+
requirement: &13632820 !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: *13632820
|
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: -946876484673399883
|
98
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
99
|
none: false
|
100
100
|
requirements:
|