mongo_delegate 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,30 @@
1
+ <p>= MongoDelegate</p>
2
+ <p>A DelegateCollection wraps a local collection and remote collection in one object that implements the Collection interface.</p>
3
+ <ul>
4
+ <li>All reads are first done on the local collection, then supplemented by a read on the remote collection, if necessary.</li>
5
+ <li>All write occur in the local collection. The remote collection is treated as read-only.</li>
6
+ </ul>
7
+ <p>This was inspired by things I&#8217;ve been told about Goldman Sachs&#8217; proprietary object database. You can point one database at another remote database, and it will function in this manner.</p>
8
+ <p>The classic use case is debugging a production problem, or developing while using production data.</p>
9
+ <ul>
10
+ <li>The annoying way: Generate data that mimics production, get a production dump and load it locally, or &#8220;test&#8221; in production while walking on eggshells to make sure not to break anything</li>
11
+ <li>The easy way: Have your local app use a delegating collection that points at the production db. Your app will be using live production data, but all writes occur locally. As writes occur, the app will get your newly written data for those documents. Your app can be oblivious to the delegation and function normally, and you can modify data without fear.</li>
12
+ </ul>
13
+ <p>Just create a DelegatingDatabase and pass to your application, wherever you would normally supply a database<br />
14
+ db = Mongo::DelegatingDatabase.new(:local =&gt; Mongo::Connection.new.db(&#8216;db-name&#8217;), :remote =&gt; Mongo::Connection.new(&#8216;remote ip&#8217;).db(&#8216;db-name&#8217;))<br />
15
+ <br />
16
+ Later, anywhere collections are retrieved in your app<br />
17
+ coll = db.collection(&#8216;some-collection-name&#8217;) # This returns an instance of Mongo::DelegatingCollection</p>
18
+ <p>== Note on Patches/Pull Requests</p>
19
+ <ul>
20
+ <li>Fork the project.</li>
21
+ <li>Make your feature addition or bug fix.</li>
22
+ <li>Add tests for it. This is important so I don&#8217;t break it in a<br />
23
+ future version unintentionally.</li>
24
+ <li>Commit, do not mess with rakefile, version, or history.<br />
25
+ (if you want to have your own version, that is fine but<br />
26
+ bump version in a commit by itself I can ignore when I pull)</li>
27
+ <li>Send me a pull request. Bonus points for topic branches.</li>
28
+ </ul>
29
+ <p>== Copyright</p>
30
+ <p>Copyright &#169; 2010 Mike Harris. See <span class="caps">LICENSE</span> for details.</p>
data/README.html ADDED
@@ -0,0 +1,30 @@
1
+ <p>= MongoDelegate</p>
2
+ <p>A DelegateCollection wraps a local collection and remote collection in one object that implements the Collection interface.</p>
3
+ <ul>
4
+ <li>All reads are first done on the local collection, then supplemented by a read on the remote collection, if necessary.</li>
5
+ <li>All write occur in the local collection. The remote collection is treated as read-only.</li>
6
+ </ul>
7
+ <p>This was inspired by things I&#8217;ve been told about Goldman Sachs&#8217; proprietary object database. You can point one database at another remote database, and it will function in this manner.</p>
8
+ <p>The classic use case is debugging a production problem, or developing while using production data.</p>
9
+ <ul>
10
+ <li>The annoying way: Generate data that mimics production, get a production dump and load it locally, or &#8220;test&#8221; in production while walking on eggshells to make sure not to break anything</li>
11
+ <li>The easy way: Have your local app use a delegating collection that points at the production db. Your app will be using live production data, but all writes occur locally. As writes occur, the app will get your newly written data for those documents. Your app can be oblivious to the delegation and function normally, and you can modify data without fear.</li>
12
+ </ul>
13
+ <p>Just create a DelegatingDatabase and pass to your application, wherever you would normally supply a database<br />
14
+ db = Mongo::DelegatingDatabase.new(:local =&gt; Mongo::Connection.new.db(&#8216;db-name&#8217;), :remote =&gt; Mongo::Connection.new(&#8216;remote ip&#8217;).db(&#8216;db-name&#8217;))<br />
15
+ <br />
16
+ Later, anywhere collections are retrieved in your app<br />
17
+ coll = db.collection(&#8216;some-collection-name&#8217;) # This returns an instance of Mongo::DelegatingCollection</p>
18
+ <p>== Note on Patches/Pull Requests</p>
19
+ <ul>
20
+ <li>Fork the project.</li>
21
+ <li>Make your feature addition or bug fix.</li>
22
+ <li>Add tests for it. This is important so I don&#8217;t break it in a<br />
23
+ future version unintentionally.</li>
24
+ <li>Commit, do not mess with rakefile, version, or history.<br />
25
+ (if you want to have your own version, that is fine but<br />
26
+ bump version in a commit by itself I can ignore when I pull)</li>
27
+ <li>Send me a pull request. Bonus points for topic branches.</li>
28
+ </ul>
29
+ <p>== Copyright</p>
30
+ <p>Copyright &#169; 2010 Mike Harris. See <span class="caps">LICENSE</span> for details.</p>
data/README.rdoc CHANGED
@@ -1,6 +1,31 @@
1
- = mongo_delegate
1
+ = MongoDelegate
2
2
 
3
- A DelegateCollection wraps
3
+ A DelegateCollection wraps a local collection and remote collection in one object that implements the Collection interface.
4
+ * All reads are first done on the local collection, then supplemented by a read on the remote collection, if necessary.
5
+ * All writes occur in the local collection. The remote collection is treated as read-only.
6
+
7
+ This was inspired by things I've been told about Goldman Sachs' proprietary object database. You can point one database at another remote database, and it will function in this manner.
8
+
9
+ The classic use case is debugging a production problem, or developing while using production data.
10
+
11
+ The annoying ways
12
+ * Generate data that mimics production
13
+ * get a production dump and load it locally
14
+ * "Test" in production while walking on eggshells to make sure not to break anything
15
+
16
+ The easy way
17
+ * Have your local app use a delegating collection that points at the production db.
18
+ * Your app will be using live production data, but all writes occur locally.
19
+ * As writes occur, the app will get your newly written data for those documents.
20
+ * Your app can be oblivious to the delegation and function normally, and you can modify data without fear.
21
+
22
+ Just create a DelegatingDatabase and pass to your application, wherever you would normally supply a database
23
+ db = Mongo::DelegatingDatabase.new(:local => Mongo::Connection.new.db('db-name'),
24
+ :remote => Mongo::Connection.new('remote ip').db('db-name'))
25
+
26
+ Later, anywhere collections are retrieved in your app
27
+ # This returns an instance of Mongo::DelegatingCollection
28
+ coll = db.collection('some-collection-name')
4
29
 
5
30
  == Note on Patches/Pull Requests
6
31
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -1 +1,2 @@
1
- require File.join(File.dirname(__FILE__),"mongo_delegate","delegating_collection")
1
+ require File.join(File.dirname(__FILE__),"mongo_delegate","delegating_collection")
2
+ require File.join(File.dirname(__FILE__),"mongo_delegate","delegating_database")
@@ -0,0 +1,9 @@
1
+ module Mongo
2
+ class DelegatingDatabase
3
+ attr_accessor :local, :remote
4
+ include FromHash
5
+ def collection(name)
6
+ DelegatingCollection.new(:local => local.collection(name), :remote => remote.collection(name))
7
+ end
8
+ end
9
+ end
@@ -1,9 +1,61 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
+ class Array
4
+ def num_from_bytes
5
+ return 0 if empty?
6
+ self[-1] + 256 * self[0..-2].num_from_bytes
7
+ end
8
+ def time_from_bytes
9
+ Time.at(num_from_bytes)
10
+ end
11
+ end
12
+
13
+ class Numeric
14
+ def to_bytes
15
+ return [] if self == 0
16
+ (self/256).to_bytes + [self%256]
17
+ end
18
+ def to_bytes4
19
+ res = to_bytes
20
+ while res.length < 4
21
+ res = [0] + res
22
+ end
23
+ res
24
+ end
25
+ end
26
+
27
+ class Time
28
+ def to_small_mongo_id
29
+ res = Mongo::ObjectID.new
30
+ res.data = to_i.to_bytes4 + (0...8).map { |x| 0 }
31
+ res
32
+ end
33
+ def to_big_mongo_id
34
+ res = Mongo::ObjectID.new
35
+ res.data = to_i.to_bytes4 + (0...8).map { |x| 255 }
36
+ res
37
+ end
38
+ end
39
+
40
+ class Mongo::ObjectID
41
+ attr_accessor :data
42
+ def time
43
+ data[0...4].time_from_bytes
44
+ end
45
+ end
46
+
47
+ class Hash
48
+ def created_at
49
+ self['_id'].time
50
+ end
51
+ end
52
+
3
53
  context Mongo::DelegatingCollection do
4
54
  def setup_coll
55
+ @start_time = Time.now
5
56
  @conn = Mongo::Connection.new
6
- @d = Mongo::DelegatingCollection.new(:remote => @conn.db('dc-remote').collection('abc'), :local => @conn.db('dc-local').collection('abc'))
57
+ @db = Mongo::DelegatingDatabase.new(:remote => @conn.db('dc-remote'), :local => @conn.db('dc-local'))
58
+ @d = @db.collection('abc')
7
59
  @d.remove
8
60
  @remotes = %w(Ellen Randy Barbara).each { |x| @d.remote.save(:name => x) }
9
61
  @locals = %w(Mike Lou Lowell).each { |x| @d.local.save(:name => x) }
@@ -56,6 +108,9 @@ context Mongo::DelegatingCollection do
56
108
  mock.instance_of(Mongo::Cursor).to_a.times(0)
57
109
  @d.count.should == 6
58
110
  end
111
+ it 'abc' do
112
+ @d.local.scope_gte('_id' => @start_time.to_small_mongo_id).count.should == 3
113
+ end
59
114
  # it 'count honors remote deletes' do
60
115
  # @d.remote.find.each { |x| @d.save(x) }
61
116
  # @d.remote.remove
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_delegate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Harris
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-13 00:00:00 -05:00
12
+ date: 2010-01-14 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -100,6 +100,8 @@ extensions: []
100
100
 
101
101
  extra_rdoc_files:
102
102
  - LICENSE
103
+ - README
104
+ - README.html
103
105
  - README.rdoc
104
106
  files:
105
107
  - .document
@@ -111,11 +113,14 @@ files:
111
113
  - lib/mongo_delegate.rb
112
114
  - lib/mongo_delegate/composite_cursor.rb
113
115
  - lib/mongo_delegate/delegating_collection.rb
116
+ - lib/mongo_delegate/delegating_database.rb
114
117
  - lib/mongo_delegate/ext.rb
115
118
  - spec/delegating_collection_spec.rb
116
119
  - spec/mongo_delegate_spec.rb
117
120
  - spec/spec.opts
118
121
  - spec/spec_helper.rb
122
+ - README
123
+ - README.html
119
124
  has_rdoc: true
120
125
  homepage: http://github.com/mharris717/mongo_delegate
121
126
  licenses: []