mongoo 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
@@ -3,7 +3,27 @@ module Mongoo
3
3
  ATTRIBUTE_META = {}
4
4
 
5
5
  class << self
6
- attr_accessor :conn, :db_name, :verbose_debug
6
+ attr_accessor :conn_opts, :db_name, :verbose_debug
7
+
8
+ def conn
9
+ Thread.current[:mongoo] ||= {}
10
+ Thread.current[:mongoo][:conn] ||= Mongo::Connection.new(*conn_opts)
11
+ end
12
+
13
+ def db
14
+ Thread.current[:mongoo] ||= {}
15
+ Thread.current[:mongoo][:db] ||= conn.db(db_name)
16
+ end
17
+
18
+ def reset_connection!
19
+ if Thread.current[:mongoo]
20
+ Thread.current[:mongoo][:db] = nil
21
+ if Thread.current[:mongoo][:conn]
22
+ Thread.current[:mongoo][:conn].close
23
+ Thread.current[:mongoo][:conn] = nil
24
+ end
25
+ end; true
26
+ end
7
27
 
8
28
  def mode
9
29
  :sync
@@ -12,20 +12,55 @@ module Mongoo
12
12
  end
13
13
 
14
14
  module Mongoo
15
- def self.mode
16
- :async
15
+ class FakeMutex
16
+ def initialize
17
+ end
18
+
19
+ def synchronize
20
+ yield
21
+ end
22
+
23
+ def lock
24
+ true
25
+ end
26
+
27
+ def locked?
28
+ false
29
+ end
30
+
31
+ def sleep(timeout=nil)
32
+ true
33
+ end
34
+
35
+ def try_lock
36
+ true
37
+ end
38
+
39
+ def unlock
40
+ true
41
+ end
17
42
  end
18
43
  end
19
44
 
20
- module Mongo
21
- class Pool
22
- Mongoo.suppress_warnings { TCPSocket = ::EventMachine::Synchrony::TCPSocket }
45
+ Mongoo.suppress_warnings do
46
+ module Mongo
47
+ class Connection
48
+ Mutex = Mongoo::FakeMutex
49
+ TCPSocket = TCPSocket = ::EventMachine::Synchrony::TCPSocket
50
+ end
51
+ end
52
+
53
+ module Mongo
54
+ class Pool
55
+ Mutex = Mongoo::FakeMutex
56
+ TCPSocket = TCPSocket = ::EventMachine::Synchrony::TCPSocket
57
+ end
23
58
  end
24
59
  end
25
60
 
26
- module Mongo
27
- class Connection
28
- Mongoo.suppress_warnings { TCPSocket = ::EventMachine::Synchrony::TCPSocket }
61
+ module Mongoo
62
+ def self.mode
63
+ :async
29
64
  end
30
65
  end
31
66
 
@@ -20,45 +20,25 @@ module Mongoo
20
20
  def collection_name(val=nil)
21
21
  if val
22
22
  @collection_name = val
23
- @collection = nil
24
- @collection_name
25
23
  else
26
24
  @collection_name ||= self.model_name.tableize
27
25
  end
28
26
  end
29
27
 
30
28
  def collection
31
- @collection ||= db.collection(collection_name)
29
+ db.collection(collection_name)
32
30
  end
33
31
 
34
32
  def conn
35
- @conn ||= begin
36
- Mongoo.conn || raise(Mongoo::ConnNotSet)
37
- end
38
- end
39
-
40
- def conn=(conn)
41
- @conn = conn
42
- @db = nil
43
- @collection = nil
44
- @conn
33
+ Mongoo.conn
45
34
  end
46
35
 
47
36
  def db
48
- @db ||= conn.db(db_name)
37
+ Mongoo.db
49
38
  end
50
39
 
51
40
  def db_name
52
- @db_name ||= begin
53
- Mongoo.db_name || raise(Mongoo::DbNameNotSet)
54
- end
55
- end
56
-
57
- def db_name=(db_name)
58
- @db_name = db_name
59
- @db = nil
60
- @collection = nil
61
- @db_name
41
+ Mongoo.db_name
62
42
  end
63
43
 
64
44
  def find(query={}, opts={})
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoo}
8
- s.version = "0.2.3"
8
+ s.version = "0.2.4"
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"]
@@ -21,8 +21,8 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
21
21
  $LOAD_PATH.unshift(File.dirname(__FILE__))
22
22
  require 'mongoo'
23
23
 
24
- Mongoo.conn = Mongo::Connection.new("localhost", 27017, :pool_size => 5, :timeout => 5)
25
- Mongoo.db_name = "mongoo-test"
24
+ Mongoo.conn_opts = ["localhost", 27017, :pool_size => 5, :timeout => 5]
25
+ Mongoo.db_name = "mongoo-test"
26
26
 
27
27
  class SearchIndex < Mongoo::Base
28
28
  attribute "terms", :type => :array
@@ -3,12 +3,13 @@ if ENV["MONGOO_ASYNC"]
3
3
  require 'helper'
4
4
  require "mongoo/async"
5
5
 
6
+ Mongoo.conn_opts = ["localhost", 27017, :pool_size => 5, :timeout => 5]
7
+ Mongoo.db_name = "mongoo-test"
8
+
6
9
  class TestAsync < Test::Unit::TestCase
7
10
 
8
11
  def setup
9
12
  EM.synchrony do
10
- Mongoo.conn = Mongo::Connection.new("localhost", 27017, :pool_size => 5, :timeout => 5)
11
- Mongoo.db_name = "mongoo-test"
12
13
 
13
14
  [Person, TvShow, SearchIndex].each do |obj|
14
15
  obj.drop
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mongoo
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.3
5
+ version: 0.2.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ben Myles
@@ -163,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
- hash: -2296487200507282446
166
+ hash: -1209992361420793263
167
167
  segments:
168
168
  - 0
169
169
  version: "0"