mongoo 0.2.4 → 0.3.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.
- data/CHANGELOG +10 -6
- data/Gemfile +4 -4
- data/README.rdoc +12 -55
- data/VERSION +1 -1
- data/lib/mongoo.rb +26 -18
- data/lib/mongoo/async.rb +130 -50
- data/lib/mongoo/persistence.rb +23 -6
- data/mongoo.gemspec +12 -9
- data/test/helper.rb +3 -8
- data/test/test_mongoo.rb +40 -0
- metadata +24 -13
data/CHANGELOG
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
== Changelog
|
2
2
|
|
3
|
-
=== 0.
|
3
|
+
=== 0.3.0
|
4
|
+
|
5
|
+
* refactored a bunch of connection and async related stuff. see README
|
6
|
+
|
7
|
+
=== 0.2.4
|
4
8
|
|
5
9
|
* async mode works again, but now you have to manually require:
|
6
10
|
|
7
11
|
require "mongoo/async"
|
8
|
-
Mongoo.
|
9
|
-
Mongoo.db_name
|
12
|
+
Mongoo.conn_opts = ["localhost", 27017, :pool_size => 5, :timeout => 5]
|
13
|
+
Mongoo.db_name = "mongoo-test"
|
10
14
|
|
11
15
|
see test_async.rb for an example.
|
12
16
|
|
@@ -21,10 +25,10 @@
|
|
21
25
|
|
22
26
|
* Can no longer set Mongoo.config = {...}
|
23
27
|
|
24
|
-
Set Mongoo.
|
28
|
+
Set Mongoo.conn_opts and Mongoo.db_name instead (more flexibility):
|
25
29
|
|
26
|
-
Mongoo.
|
27
|
-
Mongoo.db_name
|
30
|
+
Mongoo.conn_opts = ["localhost", 27017, :pool_size => 5, :timeout => 5]
|
31
|
+
Mongoo.db_name = "mongoo-test"
|
28
32
|
|
29
33
|
You can set these on a model level as well:
|
30
34
|
|
data/Gemfile
CHANGED
@@ -6,15 +6,15 @@ gem "i18n", ">= 0.4.1"
|
|
6
6
|
gem "activesupport", ">= 3.0.3"
|
7
7
|
gem "activemodel", ">= 3.0.3"
|
8
8
|
|
9
|
-
gem "mongo", "
|
10
|
-
|
11
|
-
gem "em-synchrony", ">= 0.2.0"
|
9
|
+
gem "mongo", "~> 1.3.1"
|
10
|
+
gem "em-synchrony", "~> 0.2.0", :require => false
|
12
11
|
|
13
12
|
# Add dependencies to develop your gem here.
|
14
13
|
# Include everything needed to run rake, tests, features, etc.
|
15
14
|
group :development do
|
15
|
+
gem "ruby-debug19", :require => 'ruby-debug'
|
16
16
|
gem "shoulda", ">= 0"
|
17
17
|
gem "bundler", "~> 1.0.0"
|
18
18
|
gem "jeweler", "~> 1.5.1"
|
19
19
|
gem "rcov", ">= 0"
|
20
|
-
end
|
20
|
+
end
|
data/README.rdoc
CHANGED
@@ -1,60 +1,17 @@
|
|
1
1
|
= mongoo
|
2
2
|
|
3
|
-
==
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
=== 0.2.1
|
16
|
-
|
17
|
-
* Identity Map now also stores results from find.to_a, find.each and find.next
|
18
|
-
|
19
|
-
=== 0.2.0
|
20
|
-
|
21
|
-
* Depends on mongo gem >= 1.3.1
|
22
|
-
|
23
|
-
|
24
|
-
* Can no longer set Mongoo.config = {...}
|
25
|
-
|
26
|
-
Set Mongoo.conn and Mongoo.db_name instead (more flexibility):
|
27
|
-
|
28
|
-
Mongoo.conn = Mongo::Connection.new("localhost", 27017, :pool_size => 5, :timeout => 5)
|
29
|
-
Mongoo.db_name = "mongoo-test"
|
30
|
-
|
31
|
-
You can set these on a model level as well:
|
32
|
-
|
33
|
-
Person.conn = Mongo::Connection.new("localhost", 30000, :pool_size => 5, :timeout => 5)
|
34
|
-
Person.db_name = "mongoo-test"
|
35
|
-
|
36
|
-
|
37
|
-
* You can optionally set the collection name on a model now:
|
38
|
-
|
39
|
-
class Person < Mongoo::Base
|
40
|
-
collection_name "spacemen"
|
41
|
-
end
|
42
|
-
|
43
|
-
|
44
|
-
* There is a new Identity Map feature available. It will only work when using find_one to
|
45
|
-
find a specific id. You need to manually turn it on:
|
46
|
-
|
47
|
-
Mongoo::IdentityMap.on!
|
48
|
-
|
49
|
-
If using it in a web application like Rails be sure to flush the map after each request:
|
50
|
-
|
51
|
-
Mongoo::IdentityMap.flush!
|
52
|
-
|
53
|
-
The map is scoped to the current thread or fiber. You can also turn the map back off:
|
54
|
-
|
55
|
-
Mongoo::IdentityMap.off!
|
56
|
-
|
57
|
-
Inspired by: http://railstips.org/blog/archives/2010/02/21/mongomapper-07-identity-map/
|
3
|
+
== Latest Version: 0.3.0
|
4
|
+
|
5
|
+
Usage (normal):
|
6
|
+
require 'mongoo'
|
7
|
+
Mongoo.conn = lambda { Mongo::Connection.new("localhost", 27017, :pool_size => 5, :timeout => 5) }
|
8
|
+
Mongoo.db = "mongoo-test"
|
9
|
+
|
10
|
+
Usage (async/em-synchrony):
|
11
|
+
require 'mongoo'
|
12
|
+
require 'mongoo/async'
|
13
|
+
Mongoo.conn = lambda { Mongo::Connection.new("localhost", 27017, :pool_size => 5, :timeout => 5) }
|
14
|
+
Mongoo.db = "mongoo-test"
|
58
15
|
|
59
16
|
== Contributing to mongoo
|
60
17
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/mongoo.rb
CHANGED
@@ -1,38 +1,46 @@
|
|
1
|
+
unless defined?(Mongo)
|
2
|
+
require "mongo"
|
3
|
+
end
|
4
|
+
|
5
|
+
# Mongoo.conn = lambda { Mongo::Connection.new("localhost", 27017, :pool_size => 5, :timeout => 5) }
|
6
|
+
# Mongoo.db = "mydb"
|
7
|
+
# Mongoo.conn => #<Mongo::Connection:0x00000100db8ac0>
|
8
|
+
|
1
9
|
module Mongoo
|
2
10
|
INDEX_META = {}
|
3
11
|
ATTRIBUTE_META = {}
|
4
12
|
|
5
13
|
class << self
|
6
|
-
attr_accessor :
|
14
|
+
attr_accessor :verbose_debug
|
7
15
|
|
8
|
-
def conn
|
9
|
-
|
10
|
-
|
16
|
+
def conn=(conn_lambda)
|
17
|
+
@conn_lambda = conn_lambda
|
18
|
+
@_conn = nil
|
19
|
+
@_db = nil
|
20
|
+
@conn_lambda
|
11
21
|
end
|
12
22
|
|
13
|
-
def db
|
14
|
-
|
15
|
-
|
23
|
+
def db=(db_name)
|
24
|
+
@db_name = db_name
|
25
|
+
@_db = nil
|
26
|
+
@db_name
|
16
27
|
end
|
17
28
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
end; true
|
29
|
+
def conn
|
30
|
+
@_conn ||= (@conn_lambda && @conn_lambda.call)
|
31
|
+
end
|
32
|
+
|
33
|
+
def db
|
34
|
+
@_db ||= (conn && conn.db(@db_name))
|
26
35
|
end
|
27
36
|
|
28
|
-
def
|
29
|
-
|
37
|
+
def async?
|
38
|
+
Mongo.async?
|
30
39
|
end
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
34
43
|
require "forwardable"
|
35
|
-
require "mongo"
|
36
44
|
|
37
45
|
require "active_support/core_ext"
|
38
46
|
require "active_model"
|
data/lib/mongoo/async.rb
CHANGED
@@ -1,71 +1,151 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
unless defined?(Mongo)
|
2
|
+
raise "!! mongoo/async must be loaded AFTER mongo !!"
|
3
|
+
end
|
4
|
+
|
5
|
+
original_verbosity = $VERBOSE
|
6
|
+
$VERBOSE = nil
|
7
|
+
|
8
|
+
require 'em-synchrony'
|
9
|
+
require 'em-synchrony/tcpsocket'
|
10
|
+
require 'em-synchrony/thread'
|
11
|
+
|
12
|
+
module Mongo
|
13
|
+
|
14
|
+
class Connection
|
15
|
+
TCPSocket = ::EventMachine::Synchrony::TCPSocket
|
16
|
+
Mutex = ::EventMachine::Synchrony::Thread::Mutex
|
17
|
+
ConditionVariable = ::EventMachine::Synchrony::Thread::ConditionVariable
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.async?
|
21
|
+
true
|
11
22
|
end
|
23
|
+
|
12
24
|
end
|
13
25
|
|
14
|
-
module Mongoo
|
15
|
-
class FakeMutex
|
16
|
-
def initialize
|
17
|
-
end
|
18
26
|
|
19
|
-
|
20
|
-
|
21
|
-
|
27
|
+
module Mongo
|
28
|
+
class EMPool
|
29
|
+
TCPSocket = ::EventMachine::Synchrony::TCPSocket
|
22
30
|
|
23
|
-
|
24
|
-
|
31
|
+
attr_accessor :host, :port, :size, :timeout, :safe, :checked_out
|
32
|
+
|
33
|
+
# Create a new pool of connections.
|
34
|
+
#
|
35
|
+
def initialize(connection, host, port, opts={})
|
36
|
+
@connection = connection
|
37
|
+
|
38
|
+
@host, @port = host, port
|
39
|
+
|
40
|
+
# Pool size and timeout.
|
41
|
+
@size = opts[:size] || 1
|
42
|
+
@timeout = opts[:timeout] || 5.0
|
43
|
+
|
44
|
+
# Operations to perform on a socket
|
45
|
+
@socket_ops = Hash.new { |h, k| h[k] = [] }
|
46
|
+
|
47
|
+
@all = []
|
48
|
+
@reserved = {} # map of in-progress connections
|
49
|
+
@available = [] # pool of free connections
|
50
|
+
@pending = [] # pending reservations (FIFO)
|
51
|
+
|
52
|
+
setup_pool!(host, port)
|
25
53
|
end
|
26
54
|
|
27
|
-
def
|
28
|
-
|
55
|
+
def setup_pool!(host, port)
|
56
|
+
@size.times do |i|
|
57
|
+
sock = checkout_new_socket(host, port)
|
58
|
+
@all << sock
|
59
|
+
@available << sock
|
60
|
+
end
|
29
61
|
end
|
30
62
|
|
31
|
-
def
|
32
|
-
|
63
|
+
def close
|
64
|
+
@all.each do |sock|
|
65
|
+
begin
|
66
|
+
sock.close
|
67
|
+
rescue IOError => ex
|
68
|
+
warn "IOError when attempting to close socket connected to #{@host}:#{@port}: #{ex.inspect}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
@host = @port = nil
|
72
|
+
@all.clear
|
73
|
+
@reserved.clear
|
74
|
+
@available.clear
|
75
|
+
@pending.clear
|
33
76
|
end
|
34
77
|
|
35
|
-
|
78
|
+
# Return a socket to the pool.
|
79
|
+
def checkin(socket)
|
80
|
+
fiber = Fiber.current
|
81
|
+
|
82
|
+
@available.push(@reserved.delete(fiber.object_id))
|
83
|
+
if pending = @pending.shift
|
84
|
+
pending.resume
|
85
|
+
end
|
36
86
|
true
|
37
87
|
end
|
38
88
|
|
39
|
-
|
40
|
-
|
89
|
+
# If a user calls DB#authenticate, and several sockets exist,
|
90
|
+
# then we need a way to apply the authentication on each socket.
|
91
|
+
# So we store the apply_authentication method, and this will be
|
92
|
+
# applied right before the next use of each socket.
|
93
|
+
def authenticate_existing
|
94
|
+
@all.each do |socket|
|
95
|
+
@socket_ops[socket] << Proc.new do
|
96
|
+
@connection.apply_saved_authentication(:socket => socket)
|
97
|
+
end
|
98
|
+
end
|
41
99
|
end
|
42
|
-
end
|
43
|
-
end
|
44
100
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
101
|
+
# Store the logout op for each existing socket to be applied before
|
102
|
+
# the next use of each socket.
|
103
|
+
def logout_existing(db)
|
104
|
+
@all.each do |socket|
|
105
|
+
@socket_ops[socket] << Proc.new do
|
106
|
+
@connection.db(db).issue_logout(:socket => socket)
|
107
|
+
end
|
108
|
+
end
|
50
109
|
end
|
51
|
-
end
|
52
110
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
111
|
+
# Check out an existing socket or create a new socket if the maximum
|
112
|
+
# pool size has not been exceeded. Otherwise, wait for the next
|
113
|
+
# available socket.
|
114
|
+
def checkout
|
115
|
+
fiber = Fiber.current
|
116
|
+
#puts "[P: #{@pending.size}, A: #{@available.size}, ALL: #{@all.size}]"
|
117
|
+
if socket = @available.pop
|
118
|
+
@reserved[fiber.object_id] = socket
|
119
|
+
socket
|
120
|
+
else
|
121
|
+
Fiber.yield @pending.push fiber
|
122
|
+
checkout
|
123
|
+
end
|
57
124
|
end
|
58
|
-
end
|
59
|
-
end
|
60
125
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
126
|
+
# Adds a new socket to the pool and checks it out.
|
127
|
+
#
|
128
|
+
# This method is called exclusively from #checkout;
|
129
|
+
# therefore, it runs within a mutex.
|
130
|
+
def checkout_new_socket(host, port)
|
131
|
+
return nil if @all.size >= @size
|
66
132
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
133
|
+
begin
|
134
|
+
socket = TCPSocket.new(host, port)
|
135
|
+
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
136
|
+
rescue => ex
|
137
|
+
raise ConnectionFailure, "Failed to connect to host #{@host} and port #{@port}: #{ex}"
|
138
|
+
end
|
139
|
+
|
140
|
+
# If any saved authentications exist, we want to apply those
|
141
|
+
# when creating new sockets.
|
142
|
+
@connection.apply_saved_authentication(:socket => socket)
|
143
|
+
|
144
|
+
socket
|
145
|
+
end; protected :checkout_new_socket
|
146
|
+
end # EMPool
|
147
|
+
end # Mongo
|
148
|
+
|
149
|
+
Mongo::Pool = Mongo::EMPool
|
150
|
+
|
151
|
+
$VERBOSE = original_verbosity
|
data/lib/mongoo/persistence.rb
CHANGED
@@ -25,20 +25,37 @@ module Mongoo
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
|
28
|
+
def conn=(conn_lambda)
|
29
|
+
@conn_lambda = conn_lambda
|
30
|
+
@_conn = nil
|
31
|
+
@_db = nil
|
32
|
+
@collection = nil
|
33
|
+
@conn_lambda
|
34
|
+
end
|
35
|
+
|
36
|
+
def db=(db_name)
|
37
|
+
@db_name = db_name
|
38
|
+
@_db = nil
|
39
|
+
@collection = nil
|
40
|
+
@db_name
|
30
41
|
end
|
31
42
|
|
32
43
|
def conn
|
33
|
-
Mongoo.conn
|
44
|
+
@_conn ||= ((@conn_lambda && @conn_lambda.call) || Mongoo.conn)
|
34
45
|
end
|
35
46
|
|
36
47
|
def db
|
37
|
-
|
48
|
+
@_db ||= begin
|
49
|
+
if db_name = (@db_name || (@conn_lambda && Mongoo.db.name))
|
50
|
+
conn.db(db_name)
|
51
|
+
else
|
52
|
+
Mongoo.db
|
53
|
+
end
|
54
|
+
end
|
38
55
|
end
|
39
56
|
|
40
|
-
def
|
41
|
-
|
57
|
+
def collection
|
58
|
+
@collection ||= db.collection(collection_name)
|
42
59
|
end
|
43
60
|
|
44
61
|
def find(query={}, 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.
|
8
|
+
s.version = "0.3.0"
|
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-05-
|
12
|
+
s.date = %q{2011-05-13}
|
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 = [
|
@@ -48,7 +48,7 @@ Gem::Specification.new do |s|
|
|
48
48
|
s.homepage = %q{http://github.com/benmyles/mongoo}
|
49
49
|
s.licenses = ["MIT"]
|
50
50
|
s.require_paths = ["lib"]
|
51
|
-
s.rubygems_version = %q{1.6.
|
51
|
+
s.rubygems_version = %q{1.6.1}
|
52
52
|
s.summary = %q{Object mapper for MongoDB}
|
53
53
|
s.test_files = [
|
54
54
|
"test/helper.rb",
|
@@ -66,8 +66,9 @@ Gem::Specification.new do |s|
|
|
66
66
|
s.add_runtime_dependency(%q<i18n>, [">= 0.4.1"])
|
67
67
|
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.3"])
|
68
68
|
s.add_runtime_dependency(%q<activemodel>, [">= 3.0.3"])
|
69
|
-
s.add_runtime_dependency(%q<mongo>, ["
|
70
|
-
s.add_runtime_dependency(%q<em-synchrony>, ["
|
69
|
+
s.add_runtime_dependency(%q<mongo>, ["~> 1.3.1"])
|
70
|
+
s.add_runtime_dependency(%q<em-synchrony>, ["~> 0.2.0"])
|
71
|
+
s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
|
71
72
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
72
73
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
73
74
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
@@ -76,8 +77,9 @@ Gem::Specification.new do |s|
|
|
76
77
|
s.add_dependency(%q<i18n>, [">= 0.4.1"])
|
77
78
|
s.add_dependency(%q<activesupport>, [">= 3.0.3"])
|
78
79
|
s.add_dependency(%q<activemodel>, [">= 3.0.3"])
|
79
|
-
s.add_dependency(%q<mongo>, ["
|
80
|
-
s.add_dependency(%q<em-synchrony>, ["
|
80
|
+
s.add_dependency(%q<mongo>, ["~> 1.3.1"])
|
81
|
+
s.add_dependency(%q<em-synchrony>, ["~> 0.2.0"])
|
82
|
+
s.add_dependency(%q<ruby-debug19>, [">= 0"])
|
81
83
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
82
84
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
83
85
|
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
@@ -87,8 +89,9 @@ Gem::Specification.new do |s|
|
|
87
89
|
s.add_dependency(%q<i18n>, [">= 0.4.1"])
|
88
90
|
s.add_dependency(%q<activesupport>, [">= 3.0.3"])
|
89
91
|
s.add_dependency(%q<activemodel>, [">= 3.0.3"])
|
90
|
-
s.add_dependency(%q<mongo>, ["
|
91
|
-
s.add_dependency(%q<em-synchrony>, ["
|
92
|
+
s.add_dependency(%q<mongo>, ["~> 1.3.1"])
|
93
|
+
s.add_dependency(%q<em-synchrony>, ["~> 0.2.0"])
|
94
|
+
s.add_dependency(%q<ruby-debug19>, [">= 0"])
|
92
95
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
93
96
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
94
97
|
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
data/test/helper.rb
CHANGED
@@ -2,12 +2,6 @@ require 'rubygems'
|
|
2
2
|
require 'bundler'
|
3
3
|
begin
|
4
4
|
groups = [:default, :development]
|
5
|
-
|
6
|
-
if ENV["MONGOO_ASYNC"]
|
7
|
-
groups << :async
|
8
|
-
else
|
9
|
-
groups << :sync
|
10
|
-
end
|
11
5
|
Bundler.setup(groups)
|
12
6
|
rescue Bundler::BundlerError => e
|
13
7
|
$stderr.puts e.message
|
@@ -16,13 +10,14 @@ rescue Bundler::BundlerError => e
|
|
16
10
|
end
|
17
11
|
require 'test/unit'
|
18
12
|
require 'shoulda'
|
13
|
+
require 'ruby-debug'
|
19
14
|
|
20
15
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
21
16
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
22
17
|
require 'mongoo'
|
23
18
|
|
24
|
-
Mongoo.
|
25
|
-
Mongoo.
|
19
|
+
Mongoo.conn = lambda { Mongo::Connection.new("localhost", 27017, :pool_size => 5, :timeout => 5) }
|
20
|
+
Mongoo.db = "mongoo-test"
|
26
21
|
|
27
22
|
class SearchIndex < Mongoo::Base
|
28
23
|
attribute "terms", :type => :array
|
data/test/test_mongoo.rb
CHANGED
@@ -9,6 +9,46 @@ class TestMongoo < Test::Unit::TestCase
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
should "be able to use a different db for each model" do
|
13
|
+
assert_equal "mongoo-test", Mongoo.db.name
|
14
|
+
assert_equal "mongoo-test", Person.db.name
|
15
|
+
|
16
|
+
Person.new(name: "mongoo-test").insert!
|
17
|
+
assert_equal 1, Person.count
|
18
|
+
assert_equal "mongoo-test", Person.find.next.name
|
19
|
+
|
20
|
+
Person.db = "mongoo-test-people"
|
21
|
+
assert_equal "mongoo-test-people", Person.db.name
|
22
|
+
|
23
|
+
assert_equal 0, Person.count
|
24
|
+
assert_equal 1, Mongoo.db.collection("people").count
|
25
|
+
|
26
|
+
Person.new(name: "mongoo-test-people").insert!
|
27
|
+
assert_equal 1, Person.count
|
28
|
+
assert_equal "mongoo-test-people", Person.find.next.name
|
29
|
+
|
30
|
+
Person.collection.drop
|
31
|
+
Person.db = nil
|
32
|
+
Person.conn = nil
|
33
|
+
|
34
|
+
assert_equal 1, Person.count
|
35
|
+
assert_equal "mongoo-test", Person.find.next.name
|
36
|
+
end
|
37
|
+
|
38
|
+
should "be able to use a different connection for each model" do
|
39
|
+
assert_equal Person.conn.object_id, Mongoo.conn.object_id
|
40
|
+
assert_equal Person.collection.db.connection.object_id, Mongoo.conn.object_id
|
41
|
+
Person.conn = lambda { Mongo::Connection.new("localhost", 27017, :pool_size => 5, :timeout => 5) }
|
42
|
+
assert_not_equal Person.conn.object_id, Mongoo.conn.object_id
|
43
|
+
|
44
|
+
assert_not_equal Person.collection.db.connection.object_id, Mongoo.conn.object_id
|
45
|
+
|
46
|
+
assert_equal Person.collection.db.connection.object_id, Person.conn.object_id
|
47
|
+
Person.conn = nil
|
48
|
+
assert_equal Person.conn.object_id, Mongoo.conn.object_id
|
49
|
+
assert_equal Person.collection.db.connection.object_id, Mongoo.conn.object_id
|
50
|
+
end
|
51
|
+
|
12
52
|
should "set and get attributes" do
|
13
53
|
p = Person.new("name" => "Ben")
|
14
54
|
assert_equal "Ben", p.g(:name)
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: mongoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ben Myles
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-13 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -51,7 +51,7 @@ dependencies:
|
|
51
51
|
requirement: &id004 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
|
-
- -
|
54
|
+
- - ~>
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: 1.3.1
|
57
57
|
type: :runtime
|
@@ -62,14 +62,14 @@ dependencies:
|
|
62
62
|
requirement: &id005 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
|
-
- -
|
65
|
+
- - ~>
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: 0.2.0
|
68
68
|
type: :runtime
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: *id005
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
|
-
name:
|
72
|
+
name: ruby-debug19
|
73
73
|
requirement: &id006 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
@@ -80,8 +80,19 @@ dependencies:
|
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: *id006
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
|
-
name:
|
83
|
+
name: shoulda
|
84
84
|
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: *id007
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: bundler
|
95
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
85
96
|
none: false
|
86
97
|
requirements:
|
87
98
|
- - ~>
|
@@ -89,10 +100,10 @@ dependencies:
|
|
89
100
|
version: 1.0.0
|
90
101
|
type: :development
|
91
102
|
prerelease: false
|
92
|
-
version_requirements: *
|
103
|
+
version_requirements: *id008
|
93
104
|
- !ruby/object:Gem::Dependency
|
94
105
|
name: jeweler
|
95
|
-
requirement: &
|
106
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
96
107
|
none: false
|
97
108
|
requirements:
|
98
109
|
- - ~>
|
@@ -100,10 +111,10 @@ dependencies:
|
|
100
111
|
version: 1.5.1
|
101
112
|
type: :development
|
102
113
|
prerelease: false
|
103
|
-
version_requirements: *
|
114
|
+
version_requirements: *id009
|
104
115
|
- !ruby/object:Gem::Dependency
|
105
116
|
name: rcov
|
106
|
-
requirement: &
|
117
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
107
118
|
none: false
|
108
119
|
requirements:
|
109
120
|
- - ">="
|
@@ -111,7 +122,7 @@ dependencies:
|
|
111
122
|
version: "0"
|
112
123
|
type: :development
|
113
124
|
prerelease: false
|
114
|
-
version_requirements: *
|
125
|
+
version_requirements: *id010
|
115
126
|
description: Simple object mapper for MongoDB
|
116
127
|
email: ben.myles@gmail.com
|
117
128
|
executables: []
|
@@ -163,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
163
174
|
requirements:
|
164
175
|
- - ">="
|
165
176
|
- !ruby/object:Gem::Version
|
166
|
-
hash: -
|
177
|
+
hash: -3196476684317221338
|
167
178
|
segments:
|
168
179
|
- 0
|
169
180
|
version: "0"
|
@@ -176,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
187
|
requirements: []
|
177
188
|
|
178
189
|
rubyforge_project:
|
179
|
-
rubygems_version: 1.6.
|
190
|
+
rubygems_version: 1.6.1
|
180
191
|
signing_key:
|
181
192
|
specification_version: 3
|
182
193
|
summary: Object mapper for MongoDB
|