mongo_mapper_ign 0.7.6 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -55,6 +55,16 @@ module MongoMapper
55
55
 
56
56
  @@database ||= MongoMapper.connection.db(@@database_name)
57
57
  end
58
+
59
+ # @api public
60
+ def self.slave_connections
61
+ @@slave_connections ||= []
62
+ end
63
+
64
+ # @api public
65
+ def self.slave_connections=(slaves = [])
66
+ @@slave_connections = slaves
67
+ end
58
68
 
59
69
  def self.config=(hash)
60
70
  @@config = hash
@@ -142,6 +142,14 @@ module MongoMapper
142
142
  def embeddable?
143
143
  false
144
144
  end
145
+
146
+ def enslave
147
+ @enslave = true
148
+ end
149
+
150
+ def enslave?
151
+ @enslave ||= false
152
+ end
145
153
 
146
154
  def single_collection_inherited?
147
155
  keys.key?(:_type) && single_collection_inherited_superclass?
@@ -15,6 +15,15 @@ module MongoMapper
15
15
  @connection
16
16
  end
17
17
 
18
+ def slave_connection
19
+ not_supported_by_embedded
20
+ raise "Slave connections have not been configured" if MongoMapper.slave_connections.empty?
21
+ @slave_idx ||= 0
22
+ conn = MongoMapper.slave_connections[@slave_idx]
23
+ increment_slave_idx
24
+ conn
25
+ end
26
+
18
27
  def set_database_name(name)
19
28
  not_supported_by_embedded
20
29
  @database_name = name
@@ -33,6 +42,16 @@ module MongoMapper
33
42
  connection.db(database_name)
34
43
  end
35
44
  end
45
+
46
+ def slave_database
47
+ not_supported_by_embedded
48
+ conn = slave_connection
49
+ if database_name.nil?
50
+ conn.db(MongoMapper.database.name)
51
+ else
52
+ conn.db(database_name)
53
+ end
54
+ end
36
55
 
37
56
  def set_collection_name(name)
38
57
  not_supported_by_embedded
@@ -48,11 +67,20 @@ module MongoMapper
48
67
  not_supported_by_embedded
49
68
  database.collection(collection_name)
50
69
  end
70
+
71
+ def slave_collection
72
+ not_supported_by_embedded
73
+ slave_database.collection(collection_name)
74
+ end
51
75
 
52
76
  private
53
77
  def not_supported_by_embedded
54
78
  raise Unsupported.new('This is not supported for embeddable documents at this time.') if embeddable?
55
79
  end
80
+
81
+ def increment_slave_idx
82
+ @slave_idx = @slave_idx + 1 <= MongoMapper.slave_connections.length-1 ? @slave_idx + 1 : 0
83
+ end
56
84
  end
57
85
 
58
86
  module InstanceMethods
@@ -14,7 +14,11 @@ module MongoMapper
14
14
  end
15
15
 
16
16
  def query
17
- @query ||= Plucky::Query.new(@model.collection).object_ids(@model.object_id_keys)
17
+ if @model.enslave?
18
+ @query ||= Plucky::Query.new(@model.slave_collection).object_ids(@model.object_id_keys)
19
+ else
20
+ @query ||= Plucky::Query.new(@model.collection).object_ids(@model.object_id_keys)
21
+ end
18
22
  end
19
23
 
20
24
  def add_sci_condition
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module MongoMapper
3
- Version = '0.7.6'
3
+ Version = '0.7.7'
4
4
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_mapper_ign
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 13
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 7
8
- - 6
9
- version: 0.7.6
9
+ - 7
10
+ version: 0.7.7
10
11
  platform: ruby
11
12
  authors:
12
13
  - John Nunemaker
@@ -16,16 +17,18 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2010-05-19 00:00:00 -07:00
20
+ date: 2010-06-23 00:00:00 -07:00
20
21
  default_executable: mmconsole
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
23
24
  name: activesupport
24
25
  prerelease: false
25
26
  requirement: &id001 !ruby/object:Gem::Requirement
27
+ none: false
26
28
  requirements:
27
29
  - - ">="
28
30
  - !ruby/object:Gem::Version
31
+ hash: 11
29
32
  segments:
30
33
  - 2
31
34
  - 3
@@ -37,9 +40,11 @@ dependencies:
37
40
  name: jnunemaker-validatable
38
41
  prerelease: false
39
42
  requirement: &id002 !ruby/object:Gem::Requirement
43
+ none: false
40
44
  requirements:
41
45
  - - "="
42
46
  - !ruby/object:Gem::Version
47
+ hash: 63
43
48
  segments:
44
49
  - 1
45
50
  - 8
@@ -51,9 +56,11 @@ dependencies:
51
56
  name: plucky
52
57
  prerelease: false
53
58
  requirement: &id003 !ruby/object:Gem::Requirement
59
+ none: false
54
60
  requirements:
55
61
  - - "="
56
62
  - !ruby/object:Gem::Version
63
+ hash: 31
57
64
  segments:
58
65
  - 0
59
66
  - 1
@@ -65,9 +72,11 @@ dependencies:
65
72
  name: json
66
73
  prerelease: false
67
74
  requirement: &id004 !ruby/object:Gem::Requirement
75
+ none: false
68
76
  requirements:
69
77
  - - ">="
70
78
  - !ruby/object:Gem::Version
79
+ hash: 25
71
80
  segments:
72
81
  - 1
73
82
  - 2
@@ -79,9 +88,11 @@ dependencies:
79
88
  name: jnunemaker-matchy
80
89
  prerelease: false
81
90
  requirement: &id005 !ruby/object:Gem::Requirement
91
+ none: false
82
92
  requirements:
83
93
  - - "="
84
94
  - !ruby/object:Gem::Version
95
+ hash: 15
85
96
  segments:
86
97
  - 0
87
98
  - 4
@@ -93,9 +104,11 @@ dependencies:
93
104
  name: shoulda
94
105
  prerelease: false
95
106
  requirement: &id006 !ruby/object:Gem::Requirement
107
+ none: false
96
108
  requirements:
97
109
  - - "="
98
110
  - !ruby/object:Gem::Version
111
+ hash: 35
99
112
  segments:
100
113
  - 2
101
114
  - 10
@@ -107,9 +120,11 @@ dependencies:
107
120
  name: timecop
108
121
  prerelease: false
109
122
  requirement: &id007 !ruby/object:Gem::Requirement
123
+ none: false
110
124
  requirements:
111
125
  - - "="
112
126
  - !ruby/object:Gem::Version
127
+ hash: 17
113
128
  segments:
114
129
  - 0
115
130
  - 3
@@ -121,9 +136,11 @@ dependencies:
121
136
  name: mocha
122
137
  prerelease: false
123
138
  requirement: &id008 !ruby/object:Gem::Requirement
139
+ none: false
124
140
  requirements:
125
141
  - - "="
126
142
  - !ruby/object:Gem::Version
143
+ hash: 43
127
144
  segments:
128
145
  - 0
129
146
  - 9
@@ -199,16 +216,20 @@ rdoc_options: []
199
216
  require_paths:
200
217
  - lib
201
218
  required_ruby_version: !ruby/object:Gem::Requirement
219
+ none: false
202
220
  requirements:
203
221
  - - ">="
204
222
  - !ruby/object:Gem::Version
223
+ hash: 3
205
224
  segments:
206
225
  - 0
207
226
  version: "0"
208
227
  required_rubygems_version: !ruby/object:Gem::Requirement
228
+ none: false
209
229
  requirements:
210
230
  - - ">="
211
231
  - !ruby/object:Gem::Version
232
+ hash: 23
212
233
  segments:
213
234
  - 1
214
235
  - 3
@@ -217,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
238
  requirements: []
218
239
 
219
240
  rubyforge_project:
220
- rubygems_version: 1.3.6
241
+ rubygems_version: 1.3.7
221
242
  signing_key:
222
243
  specification_version: 3
223
244
  summary: A Ruby Object Mapper for Mongo