secondbase 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,10 +1,12 @@
1
1
  = secondbase
2
2
 
3
- Secondbase adds a second database to your application. While Rails enables you to establish connections to as many external databases as you like, Rails can only manage a single database with it's migration and testing tasks.
3
+ SecondBase adds a second database to your application. While Rails enables you to establish connections to as many external databases as you like, Rails can only manage a single database with it's migration and testing tasks.
4
4
 
5
- Secondbase enables Rails to work with, and manage, a second database (almost) transparently. As a developer, you should not even realize a second database is in play. Core rake tasks such as db:create, db:migrate, and test will continue to work seamlessly with both databases without you, the developer, having to run any extra rake tasks.
5
+ SecondBase enables Rails to work with, and manage, a second database (almost) transparently. As a developer, you should not even realize a second database is in play. Core rake tasks such as rake db:create, rake db:migrate, and rake test will continue to work seamlessly with both databases without you, the developer, having to run any extra rake tasks.
6
6
 
7
- == Contributing to Secondbase
7
+ SecondBase works with Rails 2.3.x and 3.0.x. I've not tried to use SecondBase with Rails 3.1 yet, although someone has submitted a pull request fixing a 3.1 issue, so I assume it's working OK?
8
+
9
+ == Contributing to SecondBase
8
10
 
9
11
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
10
12
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
@@ -15,16 +17,16 @@ Secondbase enables Rails to work with, and manage, a second database (almost) tr
15
17
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
16
18
 
17
19
  == System Requirements
18
- Secondbase now supports Rails 2.x and Rails 3.x.
20
+ SecondBase now supports Rails 2.x and Rails 3.x.
19
21
 
20
22
  == Installation
21
- Modify your Gemfile to include Secondbase:
23
+ Modify your Gemfile to include SecondBase:
22
24
 
23
- gem 'secondbase', '0.4.0'
25
+ gem 'secondbase', '0.5.0'
24
26
 
25
27
  Run `bundle install`. You thought it would be harder? If you're using Rails 2.x, then yes, a little bit harder. You must also add this to your Rakefile:
26
28
 
27
- require 'secondbase/tasks' if defined?(Secondbase)
29
+ require 'secondbase/tasks' if defined?(SecondBase)
28
30
 
29
31
  PLEASE NOTE that if you are using bundler with Rails 2.x, then you simply need to add this to your Rakefile:
30
32
 
@@ -32,7 +34,7 @@ PLEASE NOTE that if you are using bundler with Rails 2.x, then you simply need t
32
34
 
33
35
  == Usage
34
36
  === Database
35
- Configure your database.yml to define your Secondbase:
37
+ Configure your database.yml to define your SecondBase:
36
38
 
37
39
  # Your normal rails definitions...
38
40
  development:
@@ -101,7 +103,7 @@ SecondBase offers a base model that you can simply extend:
101
103
  # you're Widget model is now pointing to your second (data)base table 'widgets'
102
104
  end
103
105
 
104
- ActiveRecord associations will still work between your Firstbase and Secondbase models!
106
+ ActiveRecord associations will still work between your Firstbase and SecondBase models!
105
107
 
106
108
  # Notice how normal this all looks...
107
109
  class User < ActiveRecord::Base
@@ -124,7 +126,7 @@ Tests can still be run using `rake test` or `rake test:units`, etc. However, if
124
126
 
125
127
  This is patch to fixtures that will identify the fixtures which belong to models that extend SecondBase::Base. The patch will then ensure that the table descendants of SecondBase::Base get loaded into your second test (data)base.
126
128
 
127
- At this time, I can verify that Secondbase works with Fixtures and Machinist. Conceivably, other test factories should work (like Factory Girl), but there is currently no support for this. If you have the time to update this gem to be test object compatible, by all means...
129
+ At this time, I can verify that SecondBase works with Fixtures, Machinist and FactoryGirl. Conceivably, other test factories should work, but there is currently no support for this. If you have the time to update this gem to be test object compatible, by all means...
128
130
 
129
131
  == TODO
130
132
  - Migration generator in Rails 3.x needs support for attribute generation (similar to rails generate migration). For example:
@@ -132,8 +134,6 @@ At this time, I can verify that Secondbase works with Fixtures and Machinist. C
132
134
 
133
135
  - rake db:fixtures:load is currently broken. Like many other things I have fixed, it assumes you only one a single database and attempts to load all fixtures into it. I don't believe we can get away with alias chaining this one, I think (like the Fixtures class), we'll have to freedom patch it.
134
136
 
135
- - secondbase needs to be tested with other factory frameworks (other then Fixtures and Machinist)
136
-
137
137
  - TESTS!! Not 100% sure how to test the rake tasks, but I can definitely write tests for the classes and generators. I did this in my spare time, sorry...
138
138
 
139
139
  == Copyright
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.3
1
+ 0.5.0
@@ -29,9 +29,7 @@ module Secondbase
29
29
  private
30
30
  # TODO: We need to add support for name/value pairs like title:string dob:date etc..
31
31
  def get_local_assigns
32
- returning(assigns = {}) do
33
- assigns[:class_name] = class_name
34
- end
32
+ { :class_name => class_name }
35
33
  end
36
34
 
37
35
  end
data/lib/secondbase.rb CHANGED
@@ -12,12 +12,25 @@ module SecondBase
12
12
 
13
13
  def self.has_runner(env)
14
14
  ActiveRecord::Base.establish_connection(SecondBase::config(env))
15
+ reset_visitor_cache
15
16
  end
16
17
 
17
18
  def self.config(env)
18
19
  ActiveRecord::Base.configurations[SecondBase::CONNECTION_PREFIX][env]
19
20
  end
20
21
 
22
+ # TODO: We should really look at faking out the connection used by ActiveRecord
23
+ # during migrations, this would prevent us from digging around Arel internals.
24
+ # Arel caches the SQL translator based on the engine (ActiveRecord::Base). This
25
+ # means that if we swap out the base connection we risk the SQL translator being wrong.
26
+ # This is an ugly hack that resets the adapter. See Line 27 of Arel's visitors.rb class.
27
+ def self.reset_visitor_cache
28
+ if Rails.version.to_i >= 3
29
+ engine = ActiveRecord::Base
30
+ adapter = engine.connection_pool.spec.config[:adapter]
31
+ Arel::Visitors::ENGINE_VISITORS[engine] = (Arel::Visitors::VISITORS[adapter] || Arel::Visitors::ToSql).new(engine)
32
+ end
33
+ end
21
34
  end
22
35
 
23
36
  module FirstBase
@@ -27,5 +40,6 @@ module FirstBase
27
40
 
28
41
  def self.has_runner(env)
29
42
  ActiveRecord::Base.establish_connection(FirstBase::config(env))
43
+ SecondBase.reset_visitor_cache
30
44
  end
31
- end
45
+ end
data/secondbase.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{secondbase}
8
- s.version = "0.4.3"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["karledurante"]
12
- s.date = %q{2011-06-22}
12
+ s.date = %q{2011-12-22}
13
13
  s.description = %q{Secondbase provides support to Rails to create a homogeneous environment for a dual database project. Using the rake tasks already familiar to you, this gem enables Rails to work with two primary databases, instead of just one.}
14
14
  s.email = %q{kdurante@customink.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secondbase
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 3
10
- version: 0.4.3
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - karledurante
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-22 00:00:00 -04:00
18
+ date: 2011-12-22 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency