mongoo 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mongoo.rb +22 -1
- data/lib/mongoo/attribute_sanitizer.rb +2 -2
- data/lib/mongoo/attributes.rb +0 -2
- data/lib/mongoo/modifiers.rb +7 -4
- data/lib/mongoo/persistence.rb +12 -11
- data/mongoo.gemspec +2 -2
- data/test/helper.rb +7 -0
- data/test/test_mongoo.rb +8 -1
- metadata +25 -25
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.7
|
data/lib/mongoo.rb
CHANGED
@@ -6,7 +6,7 @@ end
|
|
6
6
|
# Mongoo.db = "mydb"
|
7
7
|
# Mongoo.conn => #<Mongo::Connection:0x00000100db8ac0>
|
8
8
|
|
9
|
-
module Mongoo
|
9
|
+
module Mongoo
|
10
10
|
class << self
|
11
11
|
attr_accessor :verbose_debug
|
12
12
|
|
@@ -37,6 +37,27 @@ module Mongoo
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
module Mongoo
|
41
|
+
class MongooException < RuntimeError; end
|
42
|
+
|
43
|
+
class AlreadyInsertedError < MongooException; end
|
44
|
+
class NotInsertedError < MongooException; end
|
45
|
+
class InsertError < MongooException; end
|
46
|
+
class StaleUpdateError < MongooException; end
|
47
|
+
class UpdateError < MongooException; end
|
48
|
+
class RemoveError < MongooException; end
|
49
|
+
class NotValidError < MongooException; end
|
50
|
+
|
51
|
+
class DbNameNotSet < MongooException; end
|
52
|
+
class ConnNotSet < MongooException; end
|
53
|
+
|
54
|
+
class DuplicateKeyError < MongooException; end
|
55
|
+
class ModifierUpdateError < MongooException; end
|
56
|
+
class UnknownAttributeError < MongooException; end
|
57
|
+
class InvalidAttributeValue < MongooException; end
|
58
|
+
class UnknownAttributeError < MongooException; end
|
59
|
+
end
|
60
|
+
|
40
61
|
require "forwardable"
|
41
62
|
|
42
63
|
require "active_support/core_ext"
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Mongoo
|
2
|
-
class InvalidAttributeValue < Exception; end
|
3
|
-
|
4
2
|
class AttributeSanitizer
|
5
3
|
class << self
|
6
4
|
def sanitize(field_type, val)
|
7
5
|
return val if val.nil? || field_type.nil?
|
8
6
|
|
9
7
|
case field_type.to_sym
|
8
|
+
when :*
|
9
|
+
val
|
10
10
|
when :string then
|
11
11
|
val.is_a?(String) ? val : val.to_s
|
12
12
|
when :symbol then
|
data/lib/mongoo/attributes.rb
CHANGED
data/lib/mongoo/modifiers.rb
CHANGED
@@ -1,7 +1,4 @@
|
|
1
1
|
module Mongoo
|
2
|
-
class ModifierUpdateError < Exception; end
|
3
|
-
class UnknownAttributeError < Exception; end
|
4
|
-
|
5
2
|
class ModifierBuilder
|
6
3
|
def initialize(opts, doc)
|
7
4
|
@opts = opts
|
@@ -196,7 +193,13 @@ module Mongoo
|
|
196
193
|
raise ModifierUpdateError, ret.inspect
|
197
194
|
end
|
198
195
|
end # if opts[:find_any_modify]
|
199
|
-
|
196
|
+
rescue Mongo::OperationFailure => e
|
197
|
+
if e.message.to_s =~ /^11000\:/
|
198
|
+
raise Mongoo::DuplicateKeyError, e.message
|
199
|
+
else
|
200
|
+
raise e
|
201
|
+
end
|
202
|
+
end # run!
|
200
203
|
end
|
201
204
|
|
202
205
|
module Modifiers
|
data/lib/mongoo/persistence.rb
CHANGED
@@ -1,15 +1,4 @@
|
|
1
1
|
module Mongoo
|
2
|
-
class AlreadyInsertedError < Exception; end
|
3
|
-
class NotInsertedError < Exception; end
|
4
|
-
class InsertError < Exception; end
|
5
|
-
class StaleUpdateError < Exception; end
|
6
|
-
class UpdateError < Exception; end
|
7
|
-
class RemoveError < Exception; end
|
8
|
-
class NotValidError < Exception; end
|
9
|
-
|
10
|
-
class DbNameNotSet < Exception; end
|
11
|
-
class ConnNotSet < Exception; end
|
12
|
-
|
13
2
|
module Persistence
|
14
3
|
|
15
4
|
class RawUpdate
|
@@ -231,6 +220,12 @@ module Mongoo
|
|
231
220
|
end
|
232
221
|
Mongoo::IdentityMap.write(self) if Mongoo::IdentityMap.on?
|
233
222
|
ret
|
223
|
+
rescue Mongo::OperationFailure => e
|
224
|
+
if e.message.to_s =~ /^11000\:/
|
225
|
+
raise Mongoo::DuplicateKeyError, e.message
|
226
|
+
else
|
227
|
+
raise e
|
228
|
+
end
|
234
229
|
end
|
235
230
|
|
236
231
|
def insert!(opts={})
|
@@ -284,6 +279,12 @@ module Mongoo
|
|
284
279
|
end
|
285
280
|
end # if opts.delete(:find_and_modify)
|
286
281
|
end
|
282
|
+
rescue Mongo::OperationFailure => e
|
283
|
+
if e.message.to_s =~ /^11000\:/
|
284
|
+
raise Mongoo::DuplicateKeyError, e.message
|
285
|
+
else
|
286
|
+
raise e
|
287
|
+
end
|
287
288
|
end
|
288
289
|
|
289
290
|
def update!(opts={})
|
data/mongoo.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongoo}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ben Myles"]
|
12
|
-
s.date = %q{2011-06-
|
12
|
+
s.date = %q{2011-06-24}
|
13
13
|
s.description = %q{Simple object mapper for MongoDB}
|
14
14
|
s.email = %q{ben.myles@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/helper.rb
CHANGED
@@ -26,6 +26,13 @@ class SearchIndex < Mongoo::Base
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
class Contact < Mongoo::Base
|
30
|
+
describe do |o|
|
31
|
+
o.attribute "email", :type => :string
|
32
|
+
o.index "email", :unique => true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
29
36
|
class Person < Mongoo::Base
|
30
37
|
describe do |d|
|
31
38
|
d.attribute "name", :type => :string
|
data/test/test_mongoo.rb
CHANGED
@@ -3,7 +3,7 @@ require 'helper'
|
|
3
3
|
class TestMongoo < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def setup
|
6
|
-
[Person, TvShow, SearchIndex].each do |obj|
|
6
|
+
[Person, TvShow, SearchIndex, Contact].each do |obj|
|
7
7
|
obj.drop
|
8
8
|
obj.create_indexes
|
9
9
|
end
|
@@ -488,5 +488,12 @@ class TestMongoo < Test::Unit::TestCase
|
|
488
488
|
assert_equal ["skydiving", "coding", "reading", "swimming", "base jumping"], p.interests
|
489
489
|
end
|
490
490
|
|
491
|
+
should "raise a specific error if a unique constraint is violated" do
|
492
|
+
c = Contact.new(email: "foo@bar.com")
|
493
|
+
assert c.insert!
|
494
|
+
c = Contact.new(email: "foo@bar.com")
|
495
|
+
assert_raise(Mongoo::DuplicateKeyError) { c.insert! }
|
496
|
+
end
|
497
|
+
|
491
498
|
end
|
492
499
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-06-
|
12
|
+
date: 2011-06-24 00:00:00.000000000 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: i18n
|
17
|
-
requirement: &
|
17
|
+
requirement: &2152536040 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 0.4.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2152536040
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: activesupport
|
28
|
-
requirement: &
|
28
|
+
requirement: &2152534700 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 3.0.3
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2152534700
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: activemodel
|
39
|
-
requirement: &
|
39
|
+
requirement: &2152533160 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 3.0.3
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2152533160
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: mongo
|
50
|
-
requirement: &
|
50
|
+
requirement: &2152531560 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 1.3.1
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2152531560
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: ruby-debug19
|
61
|
-
requirement: &
|
61
|
+
requirement: &2152529860 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *2152529860
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: shoulda
|
72
|
-
requirement: &
|
72
|
+
requirement: &2152528720 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *2152528720
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: bundler
|
83
|
-
requirement: &
|
83
|
+
requirement: &2152527140 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ~>
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: 1.0.0
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *2152527140
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: jeweler
|
94
|
-
requirement: &
|
94
|
+
requirement: &2152525820 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ~>
|
@@ -99,10 +99,10 @@ dependencies:
|
|
99
99
|
version: 1.5.1
|
100
100
|
type: :development
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *2152525820
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: rcov
|
105
|
-
requirement: &
|
105
|
+
requirement: &2152524720 !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|
108
108
|
- - ! '>='
|
@@ -110,10 +110,10 @@ dependencies:
|
|
110
110
|
version: '0'
|
111
111
|
type: :development
|
112
112
|
prerelease: false
|
113
|
-
version_requirements: *
|
113
|
+
version_requirements: *2152524720
|
114
114
|
- !ruby/object:Gem::Dependency
|
115
115
|
name: perftools.rb
|
116
|
-
requirement: &
|
116
|
+
requirement: &2152523660 !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
119
119
|
- - ! '>='
|
@@ -121,10 +121,10 @@ dependencies:
|
|
121
121
|
version: '0'
|
122
122
|
type: :development
|
123
123
|
prerelease: false
|
124
|
-
version_requirements: *
|
124
|
+
version_requirements: *2152523660
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: bson_ext
|
127
|
-
requirement: &
|
127
|
+
requirement: &2152522400 !ruby/object:Gem::Requirement
|
128
128
|
none: false
|
129
129
|
requirements:
|
130
130
|
- - ~>
|
@@ -132,7 +132,7 @@ dependencies:
|
|
132
132
|
version: 1.3.1
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
|
-
version_requirements: *
|
135
|
+
version_requirements: *2152522400
|
136
136
|
description: Simple object mapper for MongoDB
|
137
137
|
email: ben.myles@gmail.com
|
138
138
|
executables: []
|
@@ -197,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
197
197
|
version: '0'
|
198
198
|
segments:
|
199
199
|
- 0
|
200
|
-
hash:
|
200
|
+
hash: 4291179620759477448
|
201
201
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
202
|
none: false
|
203
203
|
requirements:
|