wye 0.0.1 → 0.0.2

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/README.rdoc CHANGED
@@ -5,10 +5,59 @@ contextual execution of database queries on alternative database connections.
5
5
  Wye's patterns are most useful to applications making use of either replicated
6
6
  or federated databases.
7
7
 
8
+ == Configuration
9
+
10
+ Alternate connections are defined under the main connection's configuration
11
+ entry. An example Rails +database.yml+ might look like the following in an
12
+ environment where the MySQL database on +master-db.example+ is being
13
+ replicated to +slave-db1.example+ and +slave-db2.example+.
14
+
15
+ production:
16
+ adapter: mysql2
17
+ username: 'username'
18
+ password: 'main password'
19
+ database: 'database'
20
+ host: 'master-db.example'
21
+ alternates:
22
+ slave1:
23
+ host: 'slave-db1.example'
24
+ password: 'slave password'
25
+ slave2:
26
+ host: 'slave-db2.example'
27
+ password: 'slave password'
28
+
29
+ Each alternate entry is merged with that of its parent entry. In this same
30
+ example, the resulting configuration for +slave1+ would be the following.
31
+
32
+ adapter: mysql2
33
+ username: 'username'
34
+ password: 'slave password'
35
+ database: 'database'
36
+ host: 'slave-db1.example'
37
+
8
38
  == Basic Usage Patterns
9
39
 
10
- (Documentation is forthcoming.)
40
+ class Model < ActiveRecord::Base; end
11
41
 
12
- == Configuration
42
+ # Calling .on executes the block on the given alternate connection
43
+ Model.on(:slave1) do
44
+ Model.find(1) # find Model 1 on the slave1 connection pool
45
+ end
46
+
47
+ # Class inheritance is respected
48
+ class DerivedModel < Model; end
49
+
50
+ Model.on(:slave1) do
51
+ Model.find(1) # on slave1 pool
52
+ DerivedModel.find(1) # on slave1 pool
53
+ end
54
+
55
+ DerivedModel.on(:slave1) do
56
+ Model.find(1) # on main pool
57
+ DerivedModel.find(1) # on slave1 pool
58
+ end
13
59
 
14
- (Documentation is forthcoming.)
60
+ # Execute everything that shares the base connection pool on slave1
61
+ ActiveRecord::Base.on(:slave1) do
62
+ # ...
63
+ end
@@ -0,0 +1,15 @@
1
+ require 'active_record'
2
+
3
+ module Wye
4
+ module ActiveRecord
5
+ module Base
6
+ module ClassMethods
7
+ def on(alternate, &blk)
8
+ connection_handler.switch.on(alternate, &blk)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ ::ActiveRecord::Base.extend(Wye::ActiveRecord::Base::ClassMethods)
@@ -1,5 +1,6 @@
1
1
  module Wye
2
2
  module ActiveRecord
3
3
  autoload :ConnectionHandler, 'wye/active_record/connection_handler'
4
+ autoload :Base, 'wye/active_record/base'
4
5
  end
5
6
  end
data/lib/wye/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wye
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wye
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-07 00:00:00.000000000 Z
12
+ date: 2012-11-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -53,6 +53,7 @@ executables: []
53
53
  extensions: []
54
54
  extra_rdoc_files: []
55
55
  files:
56
+ - lib/wye/active_record/base.rb
56
57
  - lib/wye/active_record/connection_handler.rb
57
58
  - lib/wye/active_record.rb
58
59
  - lib/wye/railtie.rb