mongoo 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/VERSION +1 -1
- data/mongoo.gemspec +0 -6
- metadata +16 -30
- data/lib/mongoo/async.rb +0 -154
- data/test/test_async.rb +0 -42
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.4
|
data/mongoo.gemspec
CHANGED
@@ -26,7 +26,6 @@ Gem::Specification.new do |s|
|
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
28
|
"lib/mongoo.rb",
|
29
|
-
"lib/mongoo/async.rb",
|
30
29
|
"lib/mongoo/attribute_proxy.rb",
|
31
30
|
"lib/mongoo/attribute_sanitizer.rb",
|
32
31
|
"lib/mongoo/base.rb",
|
@@ -40,7 +39,6 @@ Gem::Specification.new do |s|
|
|
40
39
|
"mongoo.gemspec",
|
41
40
|
"test/helper.rb",
|
42
41
|
"test/test_activemodel.rb",
|
43
|
-
"test/test_async.rb",
|
44
42
|
"test/test_identity_map.rb",
|
45
43
|
"test/test_mongohash.rb",
|
46
44
|
"test/test_mongoo.rb",
|
@@ -54,7 +52,6 @@ Gem::Specification.new do |s|
|
|
54
52
|
s.test_files = [
|
55
53
|
"test/helper.rb",
|
56
54
|
"test/test_activemodel.rb",
|
57
|
-
"test/test_async.rb",
|
58
55
|
"test/test_identity_map.rb",
|
59
56
|
"test/test_mongohash.rb",
|
60
57
|
"test/test_mongoo.rb",
|
@@ -69,7 +66,6 @@ Gem::Specification.new do |s|
|
|
69
66
|
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.3"])
|
70
67
|
s.add_runtime_dependency(%q<activemodel>, [">= 3.0.3"])
|
71
68
|
s.add_runtime_dependency(%q<mongo>, ["~> 1.3.1"])
|
72
|
-
s.add_runtime_dependency(%q<em-synchrony>, ["~> 0.2.0"])
|
73
69
|
s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
|
74
70
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
75
71
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
@@ -82,7 +78,6 @@ Gem::Specification.new do |s|
|
|
82
78
|
s.add_dependency(%q<activesupport>, [">= 3.0.3"])
|
83
79
|
s.add_dependency(%q<activemodel>, [">= 3.0.3"])
|
84
80
|
s.add_dependency(%q<mongo>, ["~> 1.3.1"])
|
85
|
-
s.add_dependency(%q<em-synchrony>, ["~> 0.2.0"])
|
86
81
|
s.add_dependency(%q<ruby-debug19>, [">= 0"])
|
87
82
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
88
83
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
@@ -96,7 +91,6 @@ Gem::Specification.new do |s|
|
|
96
91
|
s.add_dependency(%q<activesupport>, [">= 3.0.3"])
|
97
92
|
s.add_dependency(%q<activemodel>, [">= 3.0.3"])
|
98
93
|
s.add_dependency(%q<mongo>, ["~> 1.3.1"])
|
99
|
-
s.add_dependency(%q<em-synchrony>, ["~> 0.2.0"])
|
100
94
|
s.add_dependency(%q<ruby-debug19>, [">= 0"])
|
101
95
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
102
96
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: mongoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ben Myles
|
@@ -57,20 +57,9 @@ dependencies:
|
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: *id004
|
60
|
-
- !ruby/object:Gem::Dependency
|
61
|
-
name: em-synchrony
|
62
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
-
none: false
|
64
|
-
requirements:
|
65
|
-
- - ~>
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: 0.2.0
|
68
|
-
type: :runtime
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: *id005
|
71
60
|
- !ruby/object:Gem::Dependency
|
72
61
|
name: ruby-debug19
|
73
|
-
requirement: &
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
74
63
|
none: false
|
75
64
|
requirements:
|
76
65
|
- - ">="
|
@@ -78,10 +67,10 @@ dependencies:
|
|
78
67
|
version: "0"
|
79
68
|
type: :development
|
80
69
|
prerelease: false
|
81
|
-
version_requirements: *
|
70
|
+
version_requirements: *id005
|
82
71
|
- !ruby/object:Gem::Dependency
|
83
72
|
name: shoulda
|
84
|
-
requirement: &
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
85
74
|
none: false
|
86
75
|
requirements:
|
87
76
|
- - ">="
|
@@ -89,10 +78,10 @@ dependencies:
|
|
89
78
|
version: "0"
|
90
79
|
type: :development
|
91
80
|
prerelease: false
|
92
|
-
version_requirements: *
|
81
|
+
version_requirements: *id006
|
93
82
|
- !ruby/object:Gem::Dependency
|
94
83
|
name: bundler
|
95
|
-
requirement: &
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
96
85
|
none: false
|
97
86
|
requirements:
|
98
87
|
- - ~>
|
@@ -100,10 +89,10 @@ dependencies:
|
|
100
89
|
version: 1.0.0
|
101
90
|
type: :development
|
102
91
|
prerelease: false
|
103
|
-
version_requirements: *
|
92
|
+
version_requirements: *id007
|
104
93
|
- !ruby/object:Gem::Dependency
|
105
94
|
name: jeweler
|
106
|
-
requirement: &
|
95
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
107
96
|
none: false
|
108
97
|
requirements:
|
109
98
|
- - ~>
|
@@ -111,10 +100,10 @@ dependencies:
|
|
111
100
|
version: 1.5.1
|
112
101
|
type: :development
|
113
102
|
prerelease: false
|
114
|
-
version_requirements: *
|
103
|
+
version_requirements: *id008
|
115
104
|
- !ruby/object:Gem::Dependency
|
116
105
|
name: rcov
|
117
|
-
requirement: &
|
106
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
118
107
|
none: false
|
119
108
|
requirements:
|
120
109
|
- - ">="
|
@@ -122,10 +111,10 @@ dependencies:
|
|
122
111
|
version: "0"
|
123
112
|
type: :development
|
124
113
|
prerelease: false
|
125
|
-
version_requirements: *
|
114
|
+
version_requirements: *id009
|
126
115
|
- !ruby/object:Gem::Dependency
|
127
116
|
name: perftools.rb
|
128
|
-
requirement: &
|
117
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
129
118
|
none: false
|
130
119
|
requirements:
|
131
120
|
- - ">="
|
@@ -133,10 +122,10 @@ dependencies:
|
|
133
122
|
version: "0"
|
134
123
|
type: :development
|
135
124
|
prerelease: false
|
136
|
-
version_requirements: *
|
125
|
+
version_requirements: *id010
|
137
126
|
- !ruby/object:Gem::Dependency
|
138
127
|
name: bson_ext
|
139
|
-
requirement: &
|
128
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
140
129
|
none: false
|
141
130
|
requirements:
|
142
131
|
- - ~>
|
@@ -144,7 +133,7 @@ dependencies:
|
|
144
133
|
version: 1.3.1
|
145
134
|
type: :development
|
146
135
|
prerelease: false
|
147
|
-
version_requirements: *
|
136
|
+
version_requirements: *id011
|
148
137
|
description: Simple object mapper for MongoDB
|
149
138
|
email: ben.myles@gmail.com
|
150
139
|
executables: []
|
@@ -164,7 +153,6 @@ files:
|
|
164
153
|
- Rakefile
|
165
154
|
- VERSION
|
166
155
|
- lib/mongoo.rb
|
167
|
-
- lib/mongoo/async.rb
|
168
156
|
- lib/mongoo/attribute_proxy.rb
|
169
157
|
- lib/mongoo/attribute_sanitizer.rb
|
170
158
|
- lib/mongoo/base.rb
|
@@ -178,7 +166,6 @@ files:
|
|
178
166
|
- mongoo.gemspec
|
179
167
|
- test/helper.rb
|
180
168
|
- test/test_activemodel.rb
|
181
|
-
- test/test_async.rb
|
182
169
|
- test/test_identity_map.rb
|
183
170
|
- test/test_mongohash.rb
|
184
171
|
- test/test_mongoo.rb
|
@@ -197,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
197
184
|
requirements:
|
198
185
|
- - ">="
|
199
186
|
- !ruby/object:Gem::Version
|
200
|
-
hash:
|
187
|
+
hash: 2962169118481187052
|
201
188
|
segments:
|
202
189
|
- 0
|
203
190
|
version: "0"
|
@@ -217,7 +204,6 @@ summary: Object mapper for MongoDB
|
|
217
204
|
test_files:
|
218
205
|
- test/helper.rb
|
219
206
|
- test/test_activemodel.rb
|
220
|
-
- test/test_async.rb
|
221
207
|
- test/test_identity_map.rb
|
222
208
|
- test/test_mongohash.rb
|
223
209
|
- test/test_mongoo.rb
|
data/lib/mongoo/async.rb
DELETED
@@ -1,154 +0,0 @@
|
|
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
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
module Mongo
|
28
|
-
class EMPool
|
29
|
-
TCPSocket = ::EventMachine::Synchrony::TCPSocket
|
30
|
-
|
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
|
-
@host, @port = host, port
|
38
|
-
|
39
|
-
# # Pool size and timeout.
|
40
|
-
# @size = opts[:size] || 1
|
41
|
-
# @timeout = opts[:timeout] || 5.0
|
42
|
-
|
43
|
-
# # Operations to perform on a socket
|
44
|
-
# @socket_ops = Hash.new { |h, k| h[k] = [] }
|
45
|
-
|
46
|
-
# @all = []
|
47
|
-
# @reserved = {} # map of in-progress connections
|
48
|
-
# @available = [] # pool of free connections
|
49
|
-
# @pending = [] # pending reservations (FIFO)
|
50
|
-
|
51
|
-
# setup_pool!(host, port)
|
52
|
-
end
|
53
|
-
|
54
|
-
def setup_pool!(host, port)
|
55
|
-
true
|
56
|
-
# @size.times do |i|
|
57
|
-
# sock = checkout_new_socket(host, port)
|
58
|
-
# @all << sock
|
59
|
-
# @available << sock
|
60
|
-
# end
|
61
|
-
end
|
62
|
-
|
63
|
-
def close
|
64
|
-
true
|
65
|
-
# @all.each do |sock|
|
66
|
-
# begin
|
67
|
-
# sock.close
|
68
|
-
# rescue IOError => ex
|
69
|
-
# warn "IOError when attempting to close socket connected to #{@host}:#{@port}: #{ex.inspect}"
|
70
|
-
# end
|
71
|
-
# end
|
72
|
-
# @host = @port = nil
|
73
|
-
# @all.clear
|
74
|
-
# @reserved.clear
|
75
|
-
# @available.clear
|
76
|
-
# @pending.clear
|
77
|
-
end
|
78
|
-
|
79
|
-
# Return a socket to the pool.
|
80
|
-
def checkin(socket)
|
81
|
-
socket.close
|
82
|
-
# fiber = Fiber.current
|
83
|
-
# @available.push(@reserved.delete(fiber.object_id))
|
84
|
-
# if pending = @pending.shift
|
85
|
-
# pending.resume
|
86
|
-
# end
|
87
|
-
true
|
88
|
-
end
|
89
|
-
|
90
|
-
# If a user calls DB#authenticate, and several sockets exist,
|
91
|
-
# then we need a way to apply the authentication on each socket.
|
92
|
-
# So we store the apply_authentication method, and this will be
|
93
|
-
# applied right before the next use of each socket.
|
94
|
-
def authenticate_existing
|
95
|
-
true
|
96
|
-
# @all.each do |socket|
|
97
|
-
# @socket_ops[socket] << Proc.new do
|
98
|
-
# @connection.apply_saved_authentication(:socket => socket)
|
99
|
-
# end
|
100
|
-
# end
|
101
|
-
end
|
102
|
-
|
103
|
-
# Store the logout op for each existing socket to be applied before
|
104
|
-
# the next use of each socket.
|
105
|
-
def logout_existing(db)
|
106
|
-
true
|
107
|
-
# @all.each do |socket|
|
108
|
-
# @socket_ops[socket] << Proc.new do
|
109
|
-
# @connection.db(db).issue_logout(:socket => socket)
|
110
|
-
# end
|
111
|
-
# end
|
112
|
-
end
|
113
|
-
|
114
|
-
# Check out an existing socket or create a new socket if the maximum
|
115
|
-
# pool size has not been exceeded. Otherwise, wait for the next
|
116
|
-
# available socket.
|
117
|
-
def checkout
|
118
|
-
checkout_new_socket(@host, @port)
|
119
|
-
# fiber = Fiber.current
|
120
|
-
# #puts "[P: #{@pending.size}, A: #{@available.size}, ALL: #{@all.size}]"
|
121
|
-
# if socket = @available.pop
|
122
|
-
# @reserved[fiber.object_id] = socket
|
123
|
-
# socket
|
124
|
-
# else
|
125
|
-
# Fiber.yield @pending.push fiber
|
126
|
-
# checkout
|
127
|
-
# end
|
128
|
-
end
|
129
|
-
|
130
|
-
# Adds a new socket to the pool and checks it out.
|
131
|
-
#
|
132
|
-
# This method is called exclusively from #checkout;
|
133
|
-
# therefore, it runs within a mutex.
|
134
|
-
def checkout_new_socket(host, port)
|
135
|
-
# return nil if @all.size >= @size
|
136
|
-
begin
|
137
|
-
socket = TCPSocket.new(host, port)
|
138
|
-
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
139
|
-
rescue => ex
|
140
|
-
raise ConnectionFailure, "Failed to connect to host #{@host} and port #{@port}: #{ex}"
|
141
|
-
end
|
142
|
-
|
143
|
-
# If any saved authentications exist, we want to apply those
|
144
|
-
# when creating new sockets.
|
145
|
-
@connection.apply_saved_authentication(:socket => socket)
|
146
|
-
|
147
|
-
socket
|
148
|
-
end; protected :checkout_new_socket
|
149
|
-
end # EMPool
|
150
|
-
end # Mongo
|
151
|
-
|
152
|
-
Mongo::Pool = Mongo::EMPool
|
153
|
-
|
154
|
-
$VERBOSE = original_verbosity
|
data/test/test_async.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
if ENV["MONGOO_ASYNC"]
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require "mongoo/async"
|
5
|
-
|
6
|
-
Mongoo.conn_opts = ["localhost", 27017, :pool_size => 5, :timeout => 5]
|
7
|
-
Mongoo.db_name = "mongoo-test"
|
8
|
-
|
9
|
-
class TestAsync < Test::Unit::TestCase
|
10
|
-
|
11
|
-
def setup
|
12
|
-
EM.synchrony do
|
13
|
-
|
14
|
-
[Person, TvShow, SearchIndex].each do |obj|
|
15
|
-
obj.drop
|
16
|
-
obj.create_indexes
|
17
|
-
end
|
18
|
-
EventMachine.stop
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
should "set and get attributes" do
|
23
|
-
EM.synchrony do
|
24
|
-
p = Person.new("name" => "Ben")
|
25
|
-
assert_equal "Ben", p.g(:name)
|
26
|
-
assert_equal "Ben", p.get(:name)
|
27
|
-
assert_equal "Ben", p.get_attribute(:name)
|
28
|
-
p.set("location.city", "San Francisco")
|
29
|
-
assert_equal "San Francisco", p.get("location.city")
|
30
|
-
p.sets({"location.demographics.crime_rate" => :high, "location.demographics.education_quality" => :low})
|
31
|
-
assert_equal({"name"=>"Ben",
|
32
|
-
"location.demographics.crime_rate"=>:high}, p.gets(%w(name location.demographics.crime_rate)))
|
33
|
-
assert_raise(Mongoo::UnknownAttributeError) { p.set("idontexist", "foo") }
|
34
|
-
assert_raise(Mongoo::UnknownAttributeError) { p.get("idontexist") }
|
35
|
-
assert_raise(NoMethodError) { p.idontexist }
|
36
|
-
assert_raise(NoMethodError) { p.idontexist = "val" }
|
37
|
-
EventMachine.stop
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|