Permalink
Browse files

Fix bugs, can now be used as a gem!

  • Loading branch information...
1 parent 3bf262b commit 845a826f355ee8731a985f49d1170415bef02cde @dplummer dplummer committed Mar 22, 2012
Showing with 31 additions and 15 deletions.
  1. +2 −2 Gemfile.lock
  2. +1 −1 hijacker.gemspec
  3. +0 −5 init.rb
  4. +0 −1 lib/db-hijacker.rb
  5. +1 −0 lib/dbhijacker.rb
  6. +3 −1 lib/hijacker.rb
  7. +7 −3 lib/hijacker/controller_methods.rb
  8. +13 −0 lib/hijacker/database.rb
  9. +2 −0 lib/hijacker/host.rb
  10. +2 −2 spec/hijacker_spec.rb
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- db-hijacker (0.3.1)
+ dbhijacker (0.3.1)
rails (~> 2.3.14)
GEM
@@ -52,7 +52,7 @@ PLATFORMS
ruby
DEPENDENCIES
- db-hijacker!
+ dbhijacker!
rack (~> 1.1.0)
rack-test (~> 0.6.1)
rake (~> 0.9.2)
View
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
- s.name = %q{db-hijacker}
+ s.name = %q{dbhijacker}
s.homepage = "https://github.com/crystalcommerce/hijacker"
s.version = "0.3.1"
View
@@ -1,7 +1,2 @@
# Include hook code here
require 'hijacker'
-require 'hijacker/controller_methods'
-
-class ActionController::Base
- include Hijacker::ControllerMethods::Instance
-end
View
@@ -1 +0,0 @@
-require File.dirname(__FILE__) + 'hijacker'
View
@@ -0,0 +1 @@
+require File.dirname(__FILE__) + '/hijacker'
View
@@ -50,7 +50,7 @@ def self.connect(target_name, sister_name = nil, options = {})
self.sister = sister_name
# don't cache sister site
- cache_database_route(target_name, database.name) unless sister_name
+ cache_database_route(target_name, database) unless sister_name
connect_sister_site_models(target_name)
@@ -218,3 +218,5 @@ def self.reenable_query_caching
require 'hijacker/database'
require 'hijacker/alias'
require 'hijacker/host'
+require 'hijacker/middleware'
+require 'hijacker/controller_methods'
@@ -29,14 +29,18 @@ def determine_databases(host)
end
raise Hijacker::UnparseableURL, "cannot parse '#{host}'" if client.nil?
-
+
master, sister = Hijacker::Database.find_master_and_sister_for(client)
-
+
return [master, sister]
end
-
+
def render_invalid_db
render :text => "You do not appear to have an account with us (#{request.host})"
end
end
end
+
+class ActionController::Base
+ include Hijacker::ControllerMethods::Instance
+end
View
@@ -84,6 +84,19 @@ def self.connect_each(sites = all.map(&:database))
end
end
+ def self.count_each(&blk)
+ acc = {}
+ connect_each do |db|
+ count = blk.call
+ acc[db] = count if count > 0
+ end
+ width = acc.keys.map(&:length).max
+ acc.sort_by(&:last).each do |db, count|
+ puts("%#{width}s: %s" % [db, count])
+ end
+ acc
+ end
+
def self.disabled_databases
Hijacker::Database.connection.select_values("SELECT `database_name` FROM `disabled_databases`")
end
View
@@ -1,3 +1,5 @@
class Hijacker::Host < ActiveRecord::Base
+ establish_connection(Hijacker.root_config)
+
validates_format_of :hostname, :with => /^(#{URI::REGEXP::PATTERN::HOST}|#{URI::REGEXP::PATTERN::IPV6ADDR})$/
end
View
@@ -74,7 +74,7 @@
it "caches the valid route at the class level :(" do
subject.connect('master_db')
- subject.valid_routes['master_db'].should == 'master_db'
+ subject.valid_routes['master_db'].should == master
end
context "there's an alias for the master" do
@@ -88,7 +88,7 @@
it "caches the valid route at the class level :(" do
subject.connect('alias_db')
- subject.valid_routes['alias_db'].should == 'master_db'
+ subject.valid_routes['alias_db'].should == master
end
end

0 comments on commit 845a826

Please sign in to comment.